CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: c++ text files

  1. #1
    Guest

    c++ text files



    I am currently trying to access a text file throught visual c++ 5.0, I can
    access the first line of the text file using CStdioFile::ReadString class
    but I can not access any other line. The txt file is basicaly just a list of
    names , a different name on each line, "line sizes is varied 10-100 chars so
    I must access line by line ". readstring seems to be ment to access line by
    line but there is no way to move to other lines.





  2. #2
    Join Date
    Apr 1999
    Location
    tx
    Posts
    37

    Re: c++ text files

    Here is a quick and dirty example of how i would do it:


    ifstream fileToRead(fileName);
    char oneLine[100];

    if(!fileToRead)
    //exit - do whatever

    while(fileToRead.getline( oneLine, sizeof(oneLine)))
    {
    parseLine(oneLine);
    }

    if(! fileToRead.eof())
    //exit/error - do whatever





  3. #3
    Join Date
    May 1999
    Location
    CA, USA
    Posts
    586

    Re: c++ text files

    Check out my Example 16 at http://home.earthlink.net/~railro/mfc_link.html... I would consider using a CStringList object to hold the strings and which would allow you to traverse the list.

    Rail

    Recording Engineer/Software Developer
    Rail Jon Rogut Software
    [email protected]
    http://home.earthlink.net/~railro/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured