How to convert wstring into string?

前端 未结 17 1972
北海茫月
北海茫月 2020-11-22 13:10

The question is how to convert wstring to string?

I have next example :

#include 
#include 

int main()
{
    std::wstr         


        
17条回答
  •  情歌与酒
    2020-11-22 13:39

    // Embarcadero C++ Builder 
    
    // convertion string to wstring
    string str1 = "hello";
    String str2 = str1;         // typedef UnicodeString String;   -> str2 contains now u"hello";
    
    // convertion wstring to string
    String str2 = u"hello";
    string str1 = UTF8string(str2).c_str();   // -> str1 contains now "hello"
    

提交回复
热议问题