What difference between

    TCHAR* t1 = new TCHAR[5];
    wcscpy(t1,L"Happy");
    T.push_back(t1);

and

TCHAR t2[] = L"Day!";
T.push_back(t2);

In the first example, you have allocated room for 5 characters, but you need 6 to include the string's terminating null byte. Also, you have specified that "Happy" is a wide character string, which requires 12 (2x6) to properly handle it.

As for the difference between the two, you haven't defined what T is as yet. I assume a vector or similar. In the case of t1, that is a pointer, and t2 is an array (a pointer to be sure, but not necessarily in the view of the compiler).

So the issue here is one of consistent treatment of your data. If you are using pointers, then use pointers consistently. If you are using arrays, then use arrays consistently. Yes, they may work together OK, but don't make assumptions you cannot prove!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.