Xaver
Xaver

Reputation: 1001

TCHAR problem in copy

Help.

TCHAR* b;
TCHAR* c=TEXT("qwerty");

I want to allocate memory and copy content of c into b.

Upvotes: 0

Views: 3060

Answers (1)

devstuff
devstuff

Reputation: 8387

I haven't worked in C++ for a while, but from memory the easiest is something like:

b = tcscpy(new TCHAR[tcslen(c) + 1], c);

The first step allocates the buffer (+1 for an extra TCHAR for the NUL delimiter); the second step copies the entire string into that new buffer; and finally assigns the result (the buffer) to b.

Newer versions of the compiler will probably complain about not using the length-limited version of the copy routine (tcscpy_s instead of tcscpy).

Upvotes: 1

Related Questions