c++ casting string to LPCWSTR in parameter

129 Views Asked by At

I can see that i can cast a string type to LPCWSTR in a parameter like this:

myfunc(L"mystring");

But suppose i want to pass a string as a variable this time, how would i cast it with ease like above (not converting the variable):

string myStringVar = "mystring";
myfunc(myStringVar);

I tried a few things like:

myfunc(L{mystringvar});
1

There are 1 best solutions below

0
On BEST ANSWER

If you want to use a wide string you need a std::wstring. You could use it like

std::wstring myStringVar = L"mystring";
myfunc(myStringVar.c_str());