LPTSTR mystring;
mystring = new TCHAR[_tcslen(oldstring) + 1];
_tcscpy(mystring, oldstring);
... After you are done ...
delete [] mystring;
这是一个完整的程序
#include <tchar.h>
#include <windows.h>
#include <string.h>
int main()
{
LPCTSTR oldstring = _T("Hello");
LPTSTR mystring;
mystring = new TCHAR[_tcslen(oldstring) + 1];
_tcscpy(mystring, oldstring);
// Stuff
delete [] mystring;
}
它编译得很好cl /DUNICODE /D_UNICODE a.cpp
我用过tchar
宏。如果您不想使用它,那么
#include <windows.h>
#include <string.h>
int main()
{
LPCWSTR oldstring = L"Hello";
LPWSTR mystring;
mystring = new WCHAR[wcslen(oldstring) + 1];
wcscpy(mystring, oldstring);
// Stuff
delete [] mystring;
}
编译良好cl a.cpp