Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert CString to std::wstring

How can I convert from CString to std::wstring?

like image 900
subbu Avatar asked Jan 11 '10 10:01

subbu


People also ask

How do you convert std::wstring to CString?

The easiest solution is to use Unicode string literals and std::wstring: wstring z = L"nüşabə"; CString cs(z. c_str()); nameData. SetWindowTextW(cs);

What is std::wstring?

std::to_wstring in c++This function is used to convert the numerical value to the wide string i.e. it parses a numerical value of datatypes (int, long long, float, double ) to a wide string. It returns a wide string of data type wstring representing the numerical value passed in the function.

How do you convert Wstring to Lpcwstr?

This LPCWSTR is Microsoft defined. So to use them we have to include Windows. h header file into our program. To convert std::wstring to wide character array type string, we can use the function called c_str() to make it C like string and point to wide character string.

What is the difference between Wstring and string?

String overview std::string is used for standard ascii and utf-8 strings. std::wstring is used for wide-character/unicode (utf-16) strings. There is no built-in class for utf-32 strings (though you should be able to extend your own from basic_string if you need one).


1 Answers

To convert CString to std::wstring:

CString hi("Hi");
std::wstring hi2(hi);

And to go the other way, use c_str():

std::wstring hi(L"Hi");
CString hi2(hi.c_str());
like image 97
DanDan Avatar answered Sep 17 '22 01:09

DanDan