_variant_t与相关类型之间的转换 分享

来源:互联网 发布:mac pc 区别 编辑:程序博客网 时间:2024/05/01 23:21

(1)与字符串CString:
 _variant_t temp;
 CString str_wtdw;
 str_wtdw=temp.bstrVal;

(2)与整数int:

 _variant_t temp;
 int value;
 value=temp.iVal;
 //有时根据不同的整数类型需要采用相关的操作,例如:
 value=temp.intVal;

(3)与浮点数double
 _variant_t temp;
 double value;
 value=temp.dblVal;

(4)与日期型函数的转换

 _variant_t temp;
 DATE   dt;
 COleDateTime   odt;
 CString outdate;

 dt=temp.date;
 odt=COleDateTime(dt);

 outdate=odt.Format("%Y年%m月%d日");
 //这种转换方式有些问题,如果月是6月,可能会出现06月的情况


 year.Format("%d年",odt.GetYear());
 month.Format("%d月",odt.GetMonth());
 day.Format("%d日",odt.GetDay());
 outdate=year+month+day;

原创粉丝点击