要求使用CFile类读文本文件,CStdioFile不行!
每一行以回车结束,没有任何标记。
//本人试过这段代码但是无法打开文件。希望高手另赐方法
   char *str; 
   str=(LPSTR)(LPCTSTR)FilePath; 
    FILE* pFile=fopen(str,"r");
    while (!feof(pFile))
{
     char cSql[2000];
     memset(cSql,0,sizeof(cSql));
     fgets(cSql,sizeof(cSql),pFile);
     CString strTemp=cSql;        //已经读出一行来
     m_filename.Add(cSql);
}
     fclose(pFile);

解决方案 »

  1.   

    #include <stdio.h> 
        #include <stdlib.h> 
         
        void main() 
        { 
        FILE * fp; 
        char s[256]; 
        if((fp = fopen("c:\\comlog.txt", "r")) == NULL) 
        { 
         printf("Can't open file\n"); 
         return; 
        } fgets(s, 256, fp); //第一行    printf("Line1 : %s\n", s); 
    //**********************************
    //for (int i =0; i<n-1; i++)//n就是第几行了
    for (int i =0; i<3; i++)
    {
    fseek(fp, 0, SEEK_CUR);
    fgets(s, 256, fp); 
    printf("Line1 : %s\n", s); }
    //***************************************88
        fclose(fp); 
        }  
      

  2.   

    用文件流就可以了。
    FILE* file;
    file=fopen("cicqserver.ini","r");

    char inibuf[23];
    memset(inibuf,0,23);
    fscanf(file,"%s",inibuf);
    CString serverip=inibuf;
    fscanf(file,"%s",inibuf);
    CString serverport=inibuf;
    fclose(file);
      

  3.   

    就是用cstdiofile啊CString static fileopen3(CString filename)
    {
    CStdioFile timereadfile1;
    if(timereadfile1.GetFileName()=="")
    {CFileDialog dlg(true,NULL,NULL,NULL,"*.arictext|*.arictext|All files|*.*||",NULL);
    if(!timereadfile1.Open(filename,CFile::modeRead))
    {
    MessageBox(NULL,"文件打开出错,请确保路径正确,并且有足够权限!","注意",0);}
    }
    CString strr;if(timereadfile1.ReadString(strr))
    return strr;
    else
    return "";}
    楼主可以参看一下这个代码!
      

  4.   

    美国公司急招赴美编程人员,本科学历,要求至少有四年编程经验;熟练掌握ORACLE或JAVA、ASP或.NET编程语言之一;可用英语进行工作沟通;身体健康,截止日期2004年08月27日,有意者请速将简历发至[email protected],北京
      

  5.   

    换用CStdioFile,readstring一次读取一行
    CStdioFile file;
    file.open(******);
    cstring str;
    while(file.read(str))
    {
    ....
    }
      

  6.   

    “要求使用CFile类读文本文件,CStdioFile不行!”老大,别人说了只能用CFile啊。。
      

  7.   

    {
    CString m_strData2 = m_strData;
    m_strData2.Replace("Upload","translog"); HANDLE hFile;
    HANDLE hAppend;
    DWORD  dwBytesRead, dwBytesWritten, dwPos;
    BYTE   buff[4096]; // Open the existing file. hFile = CreateFile(TEXT(m_strData), // open One.txt
      GENERIC_READ,             // open for reading
      0,                        // do not share
      NULL,                     // no security
      OPEN_EXISTING,            // existing file only
      FILE_ATTRIBUTE_NORMAL,    // normal file
      NULL);                    // no attr. template if (hFile == INVALID_HANDLE_VALUE)
    {
       //printf("Could not open One.txt."); 
       return;
    } // Open the existing file, or if the file does not exist,
    // create a new file. hAppend = CreateFile(TEXT(m_strData2), // open Two.txt
    GENERIC_WRITE,            // open for writing
    FILE_SHARE_READ,          // allow multiple readers
    NULL,                     // no security
    OPEN_ALWAYS,              // open or create
    FILE_ATTRIBUTE_NORMAL,    // normal file
    NULL);                    // no attr. template if (hAppend == INVALID_HANDLE_VALUE)
    {
       //printf("Could not open Two.txt."); 
       return;
    } // Append the first file to the end of the second file.
    // Lock the second file to prevent another process from
    // accessing it while writing to it. Unlock the
    // file when writing is finished. do
    {
      if (ReadFile(hFile, buff, sizeof(buff), &dwBytesRead, NULL))
      {
    dwPos = SetFilePointer(hAppend, 0, NULL, FILE_END);
    LockFile(hAppend, dwPos, 0, dwBytesRead, 0);
    WriteFile(hAppend, buff, dwBytesRead, &dwBytesWritten, NULL);
    UnlockFile(hAppend, dwPos, 0, dwBytesRead, 0);
      }
    } while (dwBytesRead == sizeof(buff)); // Close both files. CloseHandle(hFile);
    CloseHandle(hAppend); remove(m_strData);}
      

  8.   

    用CStdioFile,有专门一行一行读的函数,好像是ReadString
      

  9.   

    谁说CStdioFile不行,你把C++当C来用当然不行