Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: Assign L"" string to WCHAR[]?

Tags:

c++

string

I have a WCHAR[]:

WCHAR foo[200];

I want to copy values into it:

if (condition)
{
    foo = L"bar";
}
else 
{
   foo = L"odp";
}

What is the best way to do this?

like image 958
Nick Heiner Avatar asked Dec 17 '22 00:12

Nick Heiner


1 Answers

wcscpy, although the superbest thing would be to use std::wstring instead.

std::wstring foo;
if (condition)
    foo = L"bar";
else 
    foo = L"odp";

Or if you insist on using wcscpy:

WCHAR foo[200];
if (condition)
    wcscpy(foo, L"bar");
else 
    wcscpy(foo, L"odp");
like image 165
avakar Avatar answered Dec 24 '22 01:12

avakar