在c ++中将std :: string转换为Unicode String

时间:2013-02-20 10:59:50

标签: c++ string unicode c++builder

我有问题。我需要将字符串类型转换为unicode。 我知道喜欢的方式

string.c_str();

但它在我的代码中不起作用。

我有功能

void modify(string infstring, string* poststring)

并且在其中我需要在备忘录中显示infstring。像一个

Form1->Memo1->Lines->Add("some text "+infstring.c_str()+" some text");

但编译器说我“E2085无效指针添加”

我如何解决我的问题?

2 个答案:

答案 0 :(得分:4)

Form1->Memo1->Lines->Add("some text "+infstring.c_str()+" some text");

应该是

Form1->Memo1->Lines->Add(("some text "+infstring+" some text").c_str());

即。您将字符串文字添加到std::string 然后使用c_str()从中获取const char*

如果Add()函数采用不同的类型,但仍未提供足够的信息来了解您所询问的内容,那么仍然无效。

答案 1 :(得分:2)

使用字符串流

#include <sstream>
std::stringstream ss;
ss << "some text" << mystring << "some text";
Form1->Memo1->Lines->Add(ss.str().c_str());
相关问题