Click to See Complete Forum and Search --> : c++ text files


July 21st, 1999, 12:39 PM
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.

cactus25
July 21st, 1999, 01:37 PM
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

Rail Jon Rogut
July 21st, 1999, 01:46 PM
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
railro@earthlink.net
http://home.earthlink.net/~railro/