I have a wchar array I need to write data into using a winapi function, and I want to get it in a std::wstring
, I know std::wstring t(wText);
works but I can't have it declared in an an if statement because it wouldn't exist outside that scope. Also I can't call the constructor in this fashion:
WCHAR wText[256];
std::wstring t = L"";
if (somecondition)
{
t = t(wText);
}
What can I do? I want the wstring
to be equal to ""
when the condition is not met and when it is met I want to get a WCHAR array into it.
你可以通过调用表达式中的构造函数来构造一个临时的std::wstring
对象:
t = std::wstring(wText);
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.