_variant_t與相關類型之間的轉換 分享

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章