C ++将UnicodeString转换为String [英] C++ convert UnicodeString into String

查看:1055
本文介绍了C ++将UnicodeString转换为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分配给AnsiStringUTF8String,然后将其写入文件而不是原始的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆