int nRetCode = 0;
CString as;
as="sdfsdfsdf";
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
CString strHello;
strHello.LoadString(IDS_HELLO);
cout << (LPCTSTR)strHello << endl;
}
char*a=new char[as.GetLength()];
strcpy(a,as);
puts(a);
delete[] a; 总是执行不料
CString as;
as="sdfsdfsdf";
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
CString strHello;
strHello.LoadString(IDS_HELLO);
cout << (LPCTSTR)strHello << endl;
}
char*a=new char[as.GetLength()];
strcpy(a,as);
puts(a);
delete[] a; 总是执行不料
char*a = new char[as.GetLength()+1];
a[as.GetLength()] = '\0';
char *a=new char[as.GetLength()+1];
strcpy(a,as);
a[as.GetLength()]='\0';
puts(a);
delete[] a;
strcpy(a,as);
a[as.GetLength()]='\0';
puts(a);
delete[] a; 放在类中 就不行了 尤其是as中的字符一长 就出现上面的错误了