Question

I'm new in c++ and have problem with converting UnicodeString to string, so now searching for easiest method to convert from one type to other.

I want to use basic windows function which needs string with UnicodeString, how to make code work?

UnicodeString Exec = "notepad";
WinExec(Exec.c_str(), 0);

Environment used is c++ builder xe2

Was it helpful?

Solution

A std::string can not store unicode data. You will need a std::wstring for that.

I've never heard of UnicodeString before, but looking at the API here:

http://docwiki.embarcadero.com/Libraries/XE2/en/System.UnicodeString_Methods

It has a function called .c_str() which returns a wchar_t* which you can then use to construct a std::wstring

If you really need a std::string, then have a look at this answer.

How to convert wstring into string?

OTHER TIPS

If you are looking for complete unicode support in C++ go for ICU API. Here is the website where you can find everything about it. http://site.icu-project.org/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top