比如有一个txt文件中有如下内容:(1).程序测试,程序测试,程序测试
A.答案a   B.答案b     C.答案c  D.答案d我的想法是选取得这个txt文件的长度,然后用一个CString指针指向这个txt文件,
然后读取.如果碰到A.的时候,就把后面的“答案a"存入一个数组中,碰到B.的时候,就把"答案b"存入另一个数组中,应该如何定义这个CString指针呀,最好有个例子,谢谢了

解决方案 »

  1.   


    CRle output,input;
    int nfile;
    char *lpBuffer;//定义缓冲区
    if(!input.Open("D:\\aa.txt",CFile::modeRead))//文件打开模式
    {
       AfxMessageBox("文件不能打开");
       return ;
    }
    int len=input.GetLength();//获取当前文件长度
    if(!output.Open("D:\\bb.txt",CFile::modeWrite|Cfile::modeCreate))
    {
       AfxMessageBox("Could not open the output file");
    return;
    }
    lpBuffer=new char[len+1];//定义文件的缓冲区
    if(lpBuffer==NULL)
    {
      AfxMessageBox(" Could not allocate the copy buffer.");
    return ;
    }
    input.Read(lpBuffer.len);//读出len长度的文件到缓冲区中
    output.Write(lpBuffer.len);//从缓冲区中写入len长度的文件
    input.Close();
    output.Close();
    delete[]lpBuffer;//删除缓冲区
    lpBuffer=NULL;
    return;
    }