char* UnicodeToANSI( const wstring& str ) { char* pElementText; int iTextLen; // wide char to multi char iTextLen = WideCharToMultiByte( CP_ACP, 0, str.c_str(), -1, NULL, 0, NULL, NULL ); pElementText = new char[iTextLen + 1]; memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) ); ::WideCharToMultiByte( CP_ACP, 0, str.c_str(), -1, pElementText, iTextLen, NULL, NULL ); return pElementText; }
//使用说明
WCHAR* buf = new WCHAR[255]; GetCurrentDirectory(255,buf);//buf输出为"D:\\VSS\\workstation\\Report\\ReportTest\\Release" wcscat(buf,_T("\\ReportTitle.txt")); //在buf后面添加"\\ReportTitle.txt" char* filename = UnicodeToANSI(buf); //宽字节转换为单字节 int ret = SaveReportTitleIndex(filename);//将文件保存起来 delete []buf;