tags:

views:

176

answers:

1

Help.

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

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

+1  A: 

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).

devstuff
thx but there is the small problem. i cannon find the headers there that function define.
Xaver
The TCHAR macros are defined in `tchar.h`, located in the same folder as the other standard headers like `stdio.h`; use: `#include <tchar.h>`
devstuff