您的位置:首页 > 编程语言 > C语言/C++

C++中TCHR转string

2016-03-11 16:34 232 查看
一般C++标准库中的string不支持宽字节,也就是unicode字符集。

所以要想将TCHAR或wchar转换成string,则需调用系统函数WideCharToMultiByte

int len = WideCharToMultiByte(CP_ACP, 0, *s, -1, NULL, 0, NULL, NULL);
char *new_str = new char[len * sizeof(char)];
WideCharToMultiByte(CP_ACP, 0, *s, -1, new_str, len, NULL, NULL);
string s(new_str);


反之,要想将多字节转换为unicode,则需使用相反的函数即可MultiByteToWideChar



若工程的字符集为unicode,则可以使用标准库的宽字符版,即名字前加w,例如wstring,wcout,wcin
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: