Convert wchar_t to char

后端 未结 9 1596
谎友^
谎友^ 2020-12-13 04:19

I was wondering is it safe to do so?

wchar_t wide = /* something */;
assert(wide >= 0 && wide < 256 &&);
char myChar = static_cast

        
9条回答
  •  眼角桃花
    2020-12-13 04:30

    An easy way is :

            wstring your_wchar_in_ws();
            string your_wchar_in_str(your_wchar_in_ws.begin(), your_wchar_in_ws.end());
            char* your_wchar_in_char =  your_wchar_in_str.c_str();
    

    I'm using this method for years :)

提交回复
热议问题