我有一个问题。我需要将字符串类型转换为 unicode。 我知道这样的方法
string.c_str();
但它在我的代码中不起作用。
我有功能
void modify(string infstring, string* poststring)
我需要在备忘录中显示 infstring。像一个
Form1->Memo1->Lines->Add("some text "+infstring.c_str()+" some text");
但编译器告诉我“E2085 无效指针添加”
我该如何解决我的问题?
最佳答案
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()
函数采用不同的类型,那仍然行不通,但是您没有提供足够的信息来了解您在询问什么。
关于c++ - 在 C++ 中将 std::string 转换为 Unicode 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14978169/