User Tools

Site Tools


c:string:string-to-wstring

Convert between std::string and std::wstring

Don't use the convert variable inside the to_wstring function. It will make it perform slower.

std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> conv_;
 
std::string wideToStr(const std::wstring& wstr) {
    return conv_.to_bytes(wstr);
}
 
std::wstring strToWide(const std::string& str) {
    return conv_.from_bytes(str);
}
c/string/string-to-wstring.txt · Last modified: 2023/07/04 19:36 by 127.0.0.1