I am developing a tiny Win32 application in C ++. I learned the basics of C ++ a long time ago, so now I'm completely confused about character strings in C ++. There was no WCHAR or TCHAR only char and String . After a little investigation, I decided not to use TCHAR .
My problem is very simple, I think, but I cannot find a clear guide on how to manipulate strings in C ++. Affected by PHP coding in the last few years, I was expecting something simple with string manipulation and was wrong!
Just all I need to do is put the new data in a character string.
WCHAR* cs = L"\0"; swprintf( cs, "NEW DATA" );
This was my first attempt. When debugging my application, I researched that swprintf only puts the first two characters in my var. I solved this problem as follows:
WCHAR cs[1000]; swprintf( cs, "NEW DATA" );
But usually this trick can fail, because in my case, the new data is not a constant value, but another variable that can be wider than 1000 characters. And my code is as follows:
WCHAR cs[1000]; WCHAR* nd1; WCHAR* nd2; wcscpy(nd1, L"Some value"); wcscpy(nd2, L"Another value"); // Actually these vars stores the path for user selected folder swprintf( cs, "The paths are %s and %s", nd1, nd2);
In this case, it is likely that the total number of characters nd1 and nd2 may be more than 1000 characters, so critical data will be lost.
The question is, how can I copy all the data I need for a WCHAR string declared this way WCHAR* wchar_var; without losing anything?
PS Since I am Russian, the question may be unclear. Let me now about this, and I will try to explain my problem more clear and complex.