Q:

Assign variable wstring to Char array in C++

I have char array as follows:
TCHAR name[256] = L"abc";

Also I have another wstring vector as follows,
std::vector<std::wstring> nameList;
nameList.push_back(L"cde");
nameList.push_back(L"fgh");

I want to assign nameList vector first element to name array,
Can any one help for that me?

A:

You can use std::copy; name is an array with a bound, but it's usage as a function argument decays to a pointer to it's first element, which satisfies the requirements for an output iterator.
So you can:
wchar_t name[256] = L"abc";

std::vector<std::wstring> nameList;
nameList.push_back(L"cde");
nameList.push_back(L"fgh");

std::copy(nameList.front().begin(), nameList.front().end(), name);

Note that: this will not add any trailing \0 terminator to the buffer; If you wanted to replace/overwrite name, you should as well just use std::wstring and save yourself some hassles

