VC++控件变量 cannot convert parameter 1 from 'char [10]' to 'class CString &'怎么解决?
//通过控件变量编写加法代码:
int num1,num2,num3;
char ch1[10],ch2[10],ch3[10];
m_edit1.GetWindowText(ch1,10);
m_edit2.GetWindowText(ch2,10);
num1=atoi(ch1);
num2=atoi(ch2);
num3=num1+num2;
itoa(num3,ch3,10);
m_edit3.GetWindowText(ch3);
//输入数字的编辑框已经定义好了成员变量的type和member。gategory选择了Control,type直接生成了Edit类型。
//编译出错:E:\Microsoft Visual Studio\MSDev98\MyProjects\ADD\TestDlg.cpp(89) : error C2664: 'void __thiscall CWnd::GetWindowTextA(class CString &) const' : cannot convert parameter 1 from 'char [10]' to 'class CString &'
A reference that is not to 'const' cannot be bound to a non-lvalue
执行 cl.exe 时出错.
ADD.exe - 1 error(s), 0 warning(s)
[解决办法]
编码不同,请改编码为多字节,或者用CString变量将ch3构造一下
[解决办法]
GetWindowTextA的参数要求一个真正的CString对象,而不是一个字符串数组
[解决办法]
CString str;m_edit3.GetWindowText(str);
[解决办法]
CString str;
m_edit1.GetWindowText(str);就可以了
[解决办法]
GetWindowTextA(LPSTR,int)
[解决办法]
up!
[解决办法]
virtual void GetWindowText( CString& str ) const;
[解决办法]