user2090826
user2090826

Reputation: 145

Converting std::string to Unicode String in c++

I have a problem. I need to convert string type to unicode. I know metod like

string.c_str();

but it doesn't work in my code.

I have function

void modify(string infstring, string* poststring)

and in it i need to display infstring in memo. Like a

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

but compiler says me "E2085 Invalid Pointer addition"

How can i solve my problem?

Upvotes: 3

Views: 19262

Answers (2)

g19fanatic
g19fanatic

Reputation: 10921

use a stringstream

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

Upvotes: 3

Jonathan Wakely
Jonathan Wakely

Reputation: 171263

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

should be

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

i.e. you add the string literals to the std::string then use c_str() to get a const char* from it.

That still won't work if the Add() function takes a different type, but you haven't given enough information to know what you're asking about.

Upvotes: 5

Related Questions