在VC编程中,经常会遇到字符串之间的转换,本文就LPTSTR转换为std::string进行探讨。
在unicode环境下,LPTSTR表示宽字符
有两种方法
1、
LPTSTR sddd = _T("ddddd");
char *ansiRemoteHost = new char[wcslen(sddd)*2+1];
memset(ansiRemoteHost,0,wcslen(sddd)*2+1);
WideCharToMultiByte(CP_ACP,WC_COMPOSITECHECK,sddd,wcslen(sddd)
,ansiRemoteHost,wcslen(sddd),NULL,NULL);
string sddddd = string(ansiRemoteHost);
2、
LPTSTR sddd = _T("ddddd");
CString sChar = CString(sddd);
USES_CONVERSION;
string sddddd = string(T2A(sChar));
当然,环境不同,转换的方法也就不一样。
本文详细介绍了在VC编程环境中,将LPTSTR类型转换为std::string的具体步骤,包括使用WideCharToMultiByte函数和CStringsChar类的方法。讨论了不同环境下的转换技巧。
2730

被折叠的 条评论
为什么被折叠?



