void inputview::OnGetword() 
{ // TODO: Add your command handler code here
CString temp("z");
int counter, linecount;
linecount = inputview::GetEditCtrl().GetLineCount();
for (counter = 0; counter < linecount; counter++)
{   
                  inputview::GetEditCtrl().GetLine(counter, LPTSTR(LPCTSTR(temp)));
expr += LPCSTR(temp);
}}
问题一:为什么CString temp("z");改成CString temp;的话,下面GetLine()的时候,temp就得不到用户输入的字符串??问题二:为什么当此函数结束的时候会引起程序异常出错?
          DAMAGE:after Normal block (...) at 0x.......
答对一个得30分,先对先得

解决方案 »

  1.   

    linecount = inputview::GetEditCtrl().GetLineCount();
    这句不应该这样写
    写成
    linecount = this->GetEditCtrl().GetLineCount();

     inputview::GetEditCtrl().GetLine(counter, LPTSTR(LPCTSTR(temp)));
    expr += LPCSTR(temp);
    改成
     inputview::GetEditCtrl().GetLine(counter, temp);
    expr += temp;
    没问题吧,你的expr是什么类型?应该是CString型吧。
      

  2.   


     inputview::GetEditCtrl().GetLine(counter, LPTSTR(LPCTSTR(temp)));
    expr += LPCSTR(temp);
    改成
    GetEditCtrl().GetLine(counter, temp);PS:提问不必要这样吧,谁在乎你那30分?
    得了你30就扯平了?大家来这里是互相帮助互相学习,不是为了这点分。
      

  3.   

    temp确实是CString类型,不过如果不用以上的方式编译是不会通过的。下边是错误提示:
    D:\Program Files\Microsoft Visual Studio\MyProjects\SyRules\inputview.cpp(87) : error C2664: 'int __thiscall CEdit::GetLine(int,char *) const' : cannot convert parameter 2 from 'class CString' to 'char *'
            No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called我说明分数的原因就是因为我提了两个问题。不想开两个贴子,所以觉得应该说清楚分数是怎么分配,并不是楼上那位朋友说的那么夸张。像这类型的技术论坛有这样的机制是非常好的,并不是在乎不在乎的问题。我知道很多人并不是为了拿分,但是我觉得既然别人能帮我解决问题,我当然要感谢人家了。这样的机制就很好。
      

  4.   

    真恐怖:
    ::GetEditCtrl().GetLine(counter, LPTSTR(LPCTSTR(temp)));
    这样的代码不死才怪,典型的内存溢出问题。
    手头没有msdn,但记得GetLine函数的第二个参数是缓存指针,也就是说,你应该申请一块内存,然后把指针传进去。GetLine函数就往这块缓存里写东西。
    你现在是把一块长度为1(或者0,如果你是用CString temp的话)的缓存地址传进去,GetLine函数可不知道你缓存空间的大小,只顾往里面写东西,很容易就会覆盖掉有用的内存区域,系统发生任何错误都有可能。
    用过儿的方法也行,那是另外一个函数了。
      

  5.   

    用这个试试,应该就可以了
    ::GetEditCtrl().GetLine(counter, temp.GetBuffer(temp.GetLength()));
      

  6.   

    LPTSTR(LPCTSTR(temp))
    尽量避免,否则会死的很惨。
      

  7.   

    LPCTSTR == const char * / const w_char *
    LPTSTR  == char * / w_char *
    硬要往常量里塞些东西进去,别人都吃饱了,还撑得下去么?
    取LPSTR缓冲区时用CString::GetBuffer()或CString::GetBufferSetLength(),但记得缓冲区写完后务必调用ReleaseBuffer();
      

  8.   

    把GetEditCtrl().GetLine(counter, LPTSTR(LPCTSTR(temp)));
    expr += LPCSTR(temp);
    写成
    temp = new char[256];//假设每行不超过256
    GetEditCtrl().GetLine(counter, temp);
    expr += CString(temp);
    应该没问题了。
    昨天看错了。
      

  9.   

    GetEditCtrl().GetLine(counter, temp.GetBuffer(temp.GetLength()));
    用这个还是会出错,谢谢各位,我知道了很多