1

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?

1

1 Answer 1

4

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); 
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, I'm used to MFC and CString, which is ASCII or Unicode depending on build settings. So, yes, it looks like I need std::wstring. But I'm blown away that I need to use raw Windows API for this and that std::wstring doesn't offer even a helper here.
@JonathanWood wstring vs string. Have a look stackoverflow.com/a/402918/1866301

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.