MFCLPCTSTR lpctstr cstring

在MFC编程和Windows 8 metro style编程中都遇到了这样的问题const char* is incompatible withLPCTSTR;在VC2008以上的版本中,LPCTSTR的宏定义如下#ifdef UNICODEtypedef LPCWSTR LPCTSTR;//常宽字符串指针#elsetypedef LPCSTR LPCTSTR;//常字符串指针#endif在MFC编程中,当用到MessageBox这函数时,不能像在VC6.0中编程那样MessageBox("nihao");而是写成MessageBox(L"nihao");或者MessageBox(_T("nihao"));//_T("")字符串之间的转换函数在WIND8 Metro style编程中也一样CreateFile2中的第一个参数要写成(L"nihao");CString aCString = "A string";charmyString[256];strcpy(myString,(LPCTSTR)aString); CString theString(_T("This is a test"));int sizeOfString = (theString.GetLength() + 1);LPTSTR lpsz = new TCHAR[sizeOfString];_tcscpy_s(lpsz, sizeOfString, theString);//... modify lpsz as much as you want CString kindOfFruit = _T("bananas");int howmany = 25;_tprintf_s(_T("You have %d %sn"), howmany,(LPCTSTR)kindOfFruit); void AddCustomer(const CString& name, constCString& address, constCString& comment = _T(""));当然在开始建立MFC工程时,可以选择非union编码方式下编程;

  

爱华网本文地址 » http://www.413yy.cn/a/25101013/187107.html

更多阅读

CString中MakeLower()函数 cstring left函数

CString::MakeLowervoid MakeLower( );说明:此成员函数将此CString对象转换为一个小写字符串。示例:下面的例子说明了如何使用CString::MakeLower。// CString::MakeLower示例:CString s( "ABC" );s.MakeLower();

COleVariant和enumVARENUM colevariant

COleVariant::COleVariantCOleVariant();COleVariant(const VARIANT& varSrc);COleVariant(const COleVariant& varSrc);COleVariant(LPCVARIANT pSrc);COleVariant(LPCTSTR lpszSrc);COleVariant(LPCTSTR lpszSrc, VARTYPE

声明:《MFCLPCTSTR lpctstr cstring》为网友死丢屁的分享!如侵犯到您的合法权益请联系我们删除