
1 // CStringTest.cpp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include <iostream> 6 #include <string> 7 #include <atlstr.h> 8 9 using namespace std; 10 11 static std::string U2A(CString cstring) 12 { 13 if (::IsBadStringPtr(cstring,-1)) 14 return ""; 15 16 int cchStr = ::WideCharToMultiByte(CP_ACP, 0, cstring, -1, NULL, 0, NULL, NULL); 17 char* pstr = new char[cchStr + 1]; 18 if(pstr != NULL) 19 ::WideCharToMultiByte(CP_ACP, 0, cstring, -1, pstr, cchStr, NULL, NULL); 20 21 pstr[cchStr] = '