Question

I've been programming many years but am very new to the the std namespace and the std::string class.

I'm writing code to read the value from Gdiplus::PropertyItem::value, which is char *.

What is the most accepted way to convert this char * value to string, which in my case is a Unicode string?

Was it helpful?

Solution

You are mentioning string but you say it's a Unicode string. So then I suppose you mean wstring. You could use the MultiByteToWideChar function to convert between the two. Something like this:

std::string str(...);
int size = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
std::wstring wstr(size, 0 );
MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstr[0], size);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top