简体   繁体   中英

c++ casting string to LPCWSTR in parameter

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});

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());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM