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

CString的链接有关问题!

2012-06-30 
CString的链接问题!!!!!!!C/C++ codevoid CWAccessorDlg::OnButton3() {CWRead wrif(wr.read()){for(int

CString的链接问题!!!!!!!

C/C++ code
void CWAccessorDlg::OnButton3() {    CWRead wr;    if(wr.read())    {    for(int i=0;i<10;i++)    {    m_show=m_show+wr.getGroupRow(i);    //    m_show.Format(_T("%s%s"),m_show,wr.getGroupRow(i));    }    UpdateData(false);    }    else AfxMessageBox("文件不存在!");}

wr.getGroupRow(i)返回CString对象,m_show是MFC文本框的CString对象,但不能利用该循环把他们连起来,如果wr.getGroupRow(0)=abc,wr.getGroupRow(1)=efg,……最后得到的只是abc!使用注释里的代码运行后报错~神马原因呐……求教……

[解决办法]
报错部分:
 m_show.Format(_T("%s%s"),m_show.GetBuffer(),wr.getGroupRow(i).GetBuffer());

 程序没有错误,看一下你的wr.getGroupRow(1),wr.getGroupRow(2),wr.getGroupRow(i)是否有值。
 可以用: 
CString temp = wr.getGroupRow(i);
m_show=m_show+temp;
单步看一下!


[解决办法]
m_show=m_show+wr.getGroupRow(i);
改成:m_show += wr.getGroupRow(i);
试试。

CString貌似有些莫名其妙的问题。
我有次这样:
m_show.Format(_T("%s%s"), (LPCTSTR)m_show, (LPCTSTR)wr.getGroupRow(i));
它也出错!

热点排行