Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ convert UnicodeString into String

Please help me somebody to convert unicodestring into string

This is how i am getting unicodestring

UnicodeString _str = OpenDialog1->FileName;

Or if it possible to write into file unicode string with ifstream or something like that?

Thanks

like image 948
user525717 Avatar asked Oct 15 '25 20:10

user525717


1 Answers

Depending on your needs, assign the UnicodeString to an AnsiString or a UTF8String, and then write that to your file instead of the original UnicodeString itself:

UnicodeString _str = OpenDialog1->FileName; 
AnsiString _astr = _str;

Or:

UnicodeString _str = OpenDialog1->FileName; 
UTF8String _ustr = _str;

To pass an AnsiString/UTF8String to an STL function, you have to either:

1) use the c_str() method:

stream << _astr.c_str();

2) construct a temp std::string:

stream << std::string(_astr.c_str(), _astr.Length());

3) in the case of AnsiString only, specify the VCL_IOSTREAM define in your project to enable AnsiString's own <<< and >> operators:

stream << _astr;
like image 73
Remy Lebeau Avatar answered Oct 17 '25 18:10

Remy Lebeau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!