连续读两行阿
比如readstring两次

解决方案 »

  1.   


    Google 搜索 CStdioFile 类的用法。
      

  2.   

    CString CMyDataBaseView::split(CString str,int index)
    {
    if(index==1)
    {
    int p = str.Find(",");
    return str.Mid(0,p);
    }
    else if(index==2)
    {
    int p = str.Find(",");
    int q = str.Find(",",p+1);
    if(q==-1)
    return str.Mid(p+1,str.GetLength()-p);
    else 
    return str.Mid(p+1,q-p-1);
    }
            else 

    CString stemp("");
    return stemp;
    }
    }
    void CMyDataBaseView::OnButtonTrackmapShow() 
    {
    // TODO: Add your control notification handler code here
    char buf[100];                 //临时保存读取出来的文件内容
    CString str; CClientDC dc(this);
    CPen pen(PS_SOLID,1,RGB(255,0,0));
    dc.SelectObject(&pen);
    CWnd* pWnd = GetDlgItem(IDC_EDIT_FILEPATH);
    pWnd->GetWindowText(m_strFilePathName);
    UpdateData(TRUE);
         // CFileException e;
       if( !f.Open( m_strFilePathName, CFile::modeCreate | CFile::modeWrite, &e ) )
       {
         //#ifdef _DEBUG
         //afxDump << "File could not be opened " << e.m_cause << "\n";
         //#endif
     MessageBox("文件没有打开");
       }   else
       {
       while(f.ReadString( buf, 99 ))
      // f.ReadString( buf, 99 );
       {
           str=buf;
           CPoint a;
           a.x=atoi(split(str,1));
           a.y=atoi(split(str,2));
           dc.MoveTo(a);        char buff[100];        f.ReadString( buff, 99 );
           str=buff;
           CPoint b;
           b.x=atoi(split(str,1));
           b.y=atoi(split(str,2));
           dc.LineTo(b);
       }
       }
    }以上是我的程序代码,我的txt文件格式如下:
    12,3,0,0,0
    34,534,1,0,0
    444,5,0,0,0
    ....
    其中前两列代表x,y坐标,我要实现的功能就是以(12,3)(34,534)(444,5)等等为坐标顺次连接成线段显示出来。
    现在编译通过,但是运行时显示出现不明错误。
    拜托各位多多帮忙!!!
      

  3.   

    while(f.ReadString( buf, 99 )) 
      // f.ReadString( buf, 99 ); 
       { 
           str=buf; 
           CPoint a; 
           a.x=atoi(split(str,1)); 
           a.y=atoi(split(str,2)); 
           dc.MoveTo(a);        char buff[100];        f.ReadString( buff, 99 ); 
           str=buff; 
           CPoint b; 
           b.x=atoi(split(str,1)); 
           b.y=atoi(split(str,2)); 
           dc.LineTo(b); 
       } 
    我就想问下这段代码,我编的有问题没。
    主要是我对ReadString函数不熟悉。
      

  4.   

    我这样编实现的是读取两行吗?
    while读取的是一行,然后在循环体内我读取的是下一行。一个循环下来,再执行的是第三行还是第二行?
    不知道楼上的能否听懂我的意思。
    我是新手,每次编译我都是整体编译,所以也不知道究竟具体是哪句有问题了。
    唉。
      

  5.   

    直接readstring好了,不用加上99

    再循环一次,将读出的是第三行
      

  6.   

    为啥要用readstring啊,多麻烦,读取出来还要转换
    直接用sprintf不就得了?或者fprintf这样的函数,用字符串格式一格式化,读出来的就是你要的类型的