首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

VC++控件变量 cannot convert parameter 1 from 'char [10]' to 'class CString &'如何

2012-03-01 
VC++控件变量cannot convert parameter 1 from char [10] to class CString &怎么解决?//通过控件变量

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对象,而不是一个字符串数组
[解决办法]

C/C++ code
CString str;m_edit3.GetWindowText(str);
[解决办法]
CString str;
m_edit1.GetWindowText(str);就可以了
[解决办法]
GetWindowTextA(LPSTR,int)
[解决办法]
up!
[解决办法]
C/C++ code
virtual void GetWindowText(   CString& str ) const;
[解决办法]
探讨

引用:
C/C++ code

virtual void GetWindowText(
CString& str
) const;

const是什么意思呢?我刚开始学,有很多的地方不懂!

[解决办法]
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);

你看你前面两个 GetWindowText 都是2个参数,
为什么第三个你只用一个参数呢?
[解决办法]
探讨
C/C++ code
CString str;
m_edit3.GetWindowText(str);

[解决办法]
探讨

引用:
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.GetWi……

热点排行