C ++将UnicodeString转换为String [英] C++ convert UnicodeString into String
问题描述
请帮助我将unicodestring转换为字符串
Please help me somebody to convert unicodestring into string
这就是我得到unicodestring的方式
This is how i am getting unicodestring
UnicodeString _str = OpenDialog1->FileName;
或者是否可以使用ifstream或类似的东西写入文件unicode字符串?
Or if it possible to write into file unicode string with ifstream or something like that?
谢谢
推荐答案
根据您的需要,将UnicodeString
分配给AnsiString
或UTF8String
,然后将其写入文件而不是原始的UnicodeString
本身:
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;
或者:
UnicodeString _str = OpenDialog1->FileName;
UTF8String _ustr = _str;
要将AnsiString
/UTF8String
传递给STL函数,您必须:
To pass an AnsiString
/UTF8String
to an STL function, you have to either:
1)使用c_str()
方法:
stream << _astr.c_str();
2)构造一个临时std::string
:
stream << std::string(_astr.c_str(), _astr.Length());
3)仅在AnsiString
的情况下,在项目中指定VCL_IOSTREAM
定义以启用AnsiString自己的<<<
和>>
运算符:
3) in the case of AnsiString
only, specify the VCL_IOSTREAM
define in your project to enable AnsiString's own <<<
and >>
operators:
stream << _astr;
这篇关于C ++将UnicodeString转换为String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!