开发者

how to convert char to wchar_t in C++ [duplicate]

开发者 https://www.devze.com 2022-12-07 21:34 出处:网络
This question already has answers here: 开发者_运维问答 How to convert string to wstring in C++ (1 answer)
This question already has answers here: 开发者_运维问答 How to convert string to wstring in C++ (1 answer) How to convert char* to wchar_t*? (9 answers) How to convert UTF-8 std::string to UTF-16 std::wstring? (6 answers) Closed 10 hours ago.

This post was edited and submitted for review 10 hours ago and failed to reopen the post:

Original close reason(s) were not resolved

If I have this below code -

string str;
wstring wstr;

for (char x : str)
{
    wstr += x;
}

Is this line wstr += x wrong? Do I need some conversion function to convert char x to wchar_t to be stored in wstr? If yes, which conversion function do I need?

Edit - I have gone through the linked answers, it mentions about converting the array of wchar_t and char -> for that for sure conversion functions are needed but my question specifically asks if a char -> wchar_t would need conversion function

0

精彩评论

暂无评论...
验证码 换一张
取 消