Convert const char* to wstring

后端 未结 7 773
难免孤独
难免孤独 2020-12-03 01:24

I\'m working on a native extension for a zinc based flash application and I need to convert a const char* to a wstring.

This is my code:

7条回答
  •  死守一世寂寞
    2020-12-03 01:32

    AFAIK this works only from C++11 and above:

    #include 
    
    // ...
    
    std::wstring stringToWstring(const std::string& t_str)
    {
        //setup converter
        typedef std::codecvt_utf8 convert_type;
        std::wstring_convert converter;
    
        //use converter (.to_bytes: wstr->str, .from_bytes: str->wstr)
        return converter.from_bytes(t_str);
    }
    

    Reference answer

提交回复
热议问题