cw:4454
cw:88
cw:23
yt:13
yt;23
yt:345
cd:88
cd:7778写一个函数,当参数为cw时就读出
cw:4454
cw:88
cw:23
当参数为yt时就读出
yt:13
yt;23
yt:345
这个问题是菜鸟级的,请各位大哥,帮一下,写详细一点

解决方案 »

  1.   

    // strKey:指定的参数 arrBuf 存放读出的数据
    // 返回:实际满足要求的条数
    int Read(CString strKey, CStringArray& arrBuf)
    {
      arrBuf.RemoveAll();
      CStdioFile f;
      BOOL b = f.Open("filename", CFile::modeRead);
      if(!b)
      {
         MessageBox("打开文件出错!");
         return -1;
       }
      CString str;
      while(f.ReadString(str))
      {
         str.TrimLeft();
         if(str.Find(strKey) == 0) arrBuf.Add(str);
      }
      f.Close();
      return arrBuf.GetSize();
    }
      

  2.   

    void CFirstPage::getdata(CString key)
    {
    CStdioFile  fl;
    BOOL   ret = TRUE;
    CString LineText;
    fl.Open("e:\\test.txt", CFile::modeRead | CFile::typeText); ret = fl.ReadString(LineText);
    while(ret)
    {
    LineText.TrimLeft();
    if((key == LineText.Left(LineText.Find(":"))) && (LineText.Find(":") != -1))
    MessageBox(LineText); ret = fl.ReadString(LineText);
    } fl.Close();
    }