这段代码在vc 6中可以,但是vs 2005错误,

来源:百度知道 编辑:UC知道 时间:2024/06/30 11:30:13
int num1,num2,num3;
TCHAR ch1[10],ch2[10],ch3[10];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,10);
num1=atoi((char*)LPCTSTR(ch1));
//num1=atoi(ch1);
num2=atoi((char*)LPCTSTR(ch2));
num3=num1+num2;
itoa( num3, (char*)LPCTSTR(ch3), 10 );
GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);

我的目的是将编辑框1和2的数值加到编辑框3中,在vs 2005中运行到编辑框3中就变了乱码,怎么回事啊

TCHAR ch1[10],ch2[10],ch3[10];

把这句话改成

CString ch1,ch2, ch3;

你再试试。。

vs2005 中默认的采用UNICODE编码,而vc6.0默认的为Asic编码
修改下vs2005编码方式,采用vc6.0的就行了

把头文件后面的.h都去掉
下面加上一行using namespace std;