_variant_t与相关类型之间的转换

来源:互联网 发布:e5 v3cpu 淘宝店推荐 编辑:程序博客网 时间:2024/05/22 14:22

(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;



0 0