由一个文件 file.text  ,其内容如下:1 0 0v
-$
ERROR -- Invalid device
R1 1 2 500
.LIB
D1 2 3 D1N4002
D2 4 2 D1N4002
V1 3 0 2
V2 0 4 1
.DC VIN -4 4 0.01
.PROBE
现在想读取 带ERROR一行的内容,请问怎么做?

解决方案 »

  1.   

    如果用MFC 用StdioFile 类按行读取,分析判断字符就能做到。
      

  2.   

    简单点的
    while(fgets(buff,100)!= NULL)
    {
     string str(buff);
     if(str.find("ERROR") != -1)
       找到error;
    ...............
    }
      

  3.   

    //................
    while(!feof(fp))
    {
    fgets(revBuf, sizeof(revBuf), fp);
    tempBuf = strstr(revBuf, "ERROR");
    if (tempBuf)
      {  cout << "找到了"; }
    }
    //revBuf, tempBuf均为字符缓冲区。fp文件指针。
      

  4.   

    CSting str;
    int i = str.find("ERROR");
      

  5.   

    别用映射,就fgets行读进来。
      

  6.   

    CStdioFile File;
    File.Open(filename,CFile::modeReadWrite);//打开文件
    CString str;
    while(File.ReadString(str))
    {
    if(strstr(str,"ERROR")!=0)
    {
    //str为带ERROR一行的内容
    }
    }
    File.Close();
      

  7.   

    同意这个,不过最好在Open和Read的时候加上异常捕获
      

  8.   

    CStdioFile File;
    CString str;
    try
    {
    File.Open(filename,CFile::modeReadWrite);//打开文件
    while(File.ReadString(str))
    {
    if(str.Find("ERROR", 0) != -1)
    {
    //str为带ERROR一行的内容
    break;
    }
    }
    }
    catch (...)
    {
    AfxMessageBox("Read Error!");
    }
    File.Close();
    最好写成这样!