void CAddDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
int num1,num2,num3;
TCHAR ch1[10],ch2[10],ch3[10];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,10); num1=_ttoi(ch1);
num2=_ttoi(ch1);
num3=num1+num2; ch3=static_cast<CString>(num3);
GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);
}
红色的那段代码出错,请高手指点一下,怎么才能把num3的数据类型转换成编辑框中输出的字符串类型?
{
// TODO: 在此添加控件通知处理程序代码
int num1,num2,num3;
TCHAR ch1[10],ch2[10],ch3[10];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,10); num1=_ttoi(ch1);
num2=_ttoi(ch1);
num3=num1+num2; ch3=static_cast<CString>(num3);
GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);
}
红色的那段代码出错,请高手指点一下,怎么才能把num3的数据类型转换成编辑框中输出的字符串类型?
整数需要“格式化”成字符串,
ch3.Format(_T("%d"), num3);
整数需要“格式化”成字符串,
ch3.Format(_T("%d"), num3);
第一、ch3是C中的字符串,CString是C++中的字符串类,ch怎么可以直接复制"10"
第二、怎么能直接转换int到cstring,即使成功了,结果也不是你想要的。
你那行代码应该改成 _itot(num3,ch,10)注意这里的"10"是指十进制,不是十个字符
还有回去看看有关unicode的知识以及mfc中实现的机制。
over