CString、char*、string、int、_bstr_t、CTime、COleDateTime相互转换,判断一个字符串是一个浮点数

CString、char*、string、int、_bstr_t、CTime、COleDateTime相互转换,判断一个字符串是一个浮点数

#include 
    using namespace std; 
    #include 
     
    { 
     CString strCString="ABC"; 
     char strchar[256],*pstr; 
     
     pstr=(LPSTR)(LPCTSTR)strCString; //CString---->char* 
     strcpy(strchar,(LPSTR)(LPCTSTR)strCString); //CString---->char[] 
     
     _bstr_t strbstr=pstr; //char*---->_bstr_t 
     WCHAR *strWCHAR=strbstr; //b_str_t--->UNICODE 
     
     strbstr=strWCHAR; 
     pstr=strbstr; //UNICODE---->char* 
     
     strCString="10"; 
     int istr=atoi((LPSTR)(LPCTSTR)strCString); //CString、char[]、char*------>int 
     strCString.Format("%d",istr); //int----->CString 
     sprintf(strchar,"%d",istr); //int----->char[] 
     
     pstr=new char[256]; //字符串申请空间 
     strcpy(pstr,"ABC"); //字符串赋值 
     delete []pstr; //字符串释放 
     
     string strstring="ABC"; 
     pstr=(char*)strstring.c_str(); //string---->char* 
     
     strCString="2003-10-27 6:24:37"; //CString--->COleDateTime 
     COleVariant vtime(strCString); 
     vtime.ChangeType(VT_DATE); 
     COleDateTime time4=vtime; 
     
     
     
     COleDateTime time1(1977,4,16,2,2,2); //COleDataTime--->CTime 
     SYSTEMTIME systime; 
     VariantTimeToSystemTime(time1, &systime); 
     CTime tm(systime); 
     
     time_t time2=tm.GetTime(); //CTime--->time_t 
     COleDateTime time3(time2); //time_t--->COleDateTime 
     
     //判断字符串是否是某种类型 
     CString sValue("123.1"); 
     COleVariant vValue(sValue); 
     
     BOOL bStrIsFloat = (SUCCEEDED(VariantChangeType(&vValue, &vValue, 0, VT_R8)) && sValue.Find('.') != -1); 
     if(bStrIsFloat) 
     { 
     AfxMessageBox("浮点"); 
     } 
    } 
原文:http://www.cnblogs.com/xtry/articles/44433.html

你可能感兴趣的:(类型转换,VC,ctime,_bstr_t,COleDateTime)