小弟现在对一个TXT文件进行读写,其格式如下:
$#DATE#$
Test-Start-Date  2006/11/13_19:17:44
Test-End-Date    2006/11/13_19:17:46
$#TESTDATA#$
Dut#     IC#   Waf#  IC(Waf)#   P/F    Bin     Cat    Xadr  Yadr
   1       1      1         1   FAIL     2       2     140   135
$#DUT1TEST#$
Test#  Pin  PF    Value  L-Limit  U-Limit Unit     DataName Comment/PinName
  101    +  *U        -        -        - -        -        VDD(-)
  101  101   P   -0.387   -1.500   -0.200 V        -        VDDC            
  101  102   P   -0.384   -1.500   -0.200 V        -        VDDA            
  101  103  *U   -0.005   -1.500   -0.200 V        -        VDDD            
  101  104   P   -0.389   -1.500   -0.200 V        -        VDDIO           
  110    +  *U        -        -        - -        -        ANALOG (-)
  110  201   P   -0.617   -1.500   -0.200 V        -        VPP             
  110  202   P   -0.516   -1.500   -0.200 V        -        VOUT            
  110  203  *U   -0.008   -1.500   -0.200 V        -        VCLX4           
  110  204   P   -0.580   -1.500   -0.200 V        -        VLCD            
  110  205   P   -0.523   -1.500   -0.200 V        -        VL5             
  110  206   P   -0.600   -1.500   -0.200 V        -        VL4             
  110  207   P   -0.555   -1.500   -0.200 V        -        VL3             
  110  208   P   -0.581   -1.500   -0.200 V        -        VL2             
  110  209   P   -0.635   -1.500   -0.200 V        -        ANALOG_TEST     
  120    =   P        - -               - -        -        LOGIC (-)
  121    =   P        - -               - -        -        LOGIC (+)
  131    =  *F        - -               - -        -        LCD odd  pin (-)
  132    =  *F        - -               - -        -        LCD even pin (-)
  133    =  *F        - -               - -        -        LCD odd pin (+)我现在想实现,在界面上输入101,就把所有101开头的那一些行全部输出到另外一个TXT中。请问怎么来实现?也就是说怎么来判断?请高手指点指点。谢谢拉~~
我用CreateFile()这个函数打开文件,属性选择read。我用GetFileSize()得到文件的大小,请问我接下来怎么来实现一行一行读呢?用什么函数???请高手给点代码吧~~谢谢拉~~

解决方案 »

  1.   

    这个好办的
    你只要按一行一行的读出来,然后提取前三个字符来跟101对比,如果相同就把这一样写到一个临时文件(或你想要的目标文件中),如果不是就读下一行,然后比较
    就这么简单的
    具体你用CString类来做就行了
      

  2.   

    大哥,能提供一些code不?谢谢拉~~
      

  3.   

    呵呵,我刚刚在别处回答了这个问题(差不多),再拷贝一份阿,呵呵
    CStdioFile f;
    char strTemp[MAX_COUNT];
    if(f.Open(strFileName,CFile::modeNoTruncate | CFile::modeRead ,NULL))
    {
             f.ReadString(strTemp,MAX_COUNT);
    f.Close();
    `         }
    利用strTemp,进行比较就可以了
      

  4.   

    f.ReadString(strTemp,MAX_COUNT);这个是读一行还是???
      

  5.   

    CStdioFile f;
    //CString buf;
    //buf = "test string";
    char* pFileName = "c:\\myfile.txt"; f.Open( (LPCTSTR)pFileName, CFile::modeCreate
    | CFile::modeWrite | CFile::typeText );
    f.WriteString( string );
    f.Close();
    为什么这个保存函数只保存了一行数据,其他的都覆盖拉???
      

  6.   

    void CReadLogFileDlg::OnOpenFile() 
    {
          CString strValue;
        CString strInputValue;
    CStdioFile file("c:\\1.txt",CFile::modeRead);
    //int length = file.GetLength();
    //file .ReadString(strValue);
            //file.ReadString(strTemp,2047);
    //file.Close();     
    while (file.ReadString(strValue))
    {
    strValue.TrimLeft(" ");
    CString str = strValue.Left(3);
    GetDlgItemText(IDC_EDIT_TEST,strInputValue);//得到输入框中的值
    if(str.CompareNoCase(strInputValue) == 0)
    {
    //相同,写到另外的一个文件
    WriteTxtFile(strValue);
    }
    }
    file.Close();
    }
     //往文件中写入字符
    void CReadLogFileDlg::WriteTxtFile(CString string)
    {
    CStdioFile f;
    //CString buf;
    //buf = "test string";
    char* pFileName = "c:\\myfile.txt"; f.Open( (LPCTSTR)pFileName, CFile::modeCreate
    | CFile::modeWrite | CFile::typeText );
    f.WriteString( string );
    f.Close();
    }
    第一个问题:我这个只能判断输入三位数才有效,怎么才能保持其通用性呢?也就是说输入任意位的数就可以查找呢?
    第二个问题:我输入三位数101,但是为什么我写的myfile.txt文件中只保存了一行呢???
      

  7.   

    写的时候要判断一下文件,或者使用CFile::SeekToEnd,就不会覆盖掉以前的了.