Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grabbing a single line from CFile read

Status
Not open for further replies.

PlasmaZero

Programmer
Dec 6, 2002
13
0
0
US
Hello, I'm making an app which requires the ability to read a single line of text from an external .txt file, use the line, and then grab the next line.
So, is there some sort of GetLine function that you can use with CFile, like myFile.GetLine(buffer)?
If not, is there a way to determine the end of a line when using the Read function, such as
myFile.Read(buffer, chars);
CString temp = buffer;
if (temp.mid(i,1) = ???)

Thanks for your time
 
GetLine you'll have to write yourself.
Here is how you can do it :
a) buffer is so big that it can hold the whole file-data.
Then you can extract line by line.
b) buffer holds 1 byte
then you you read byte by byte until you find \r\n
c) buffer holds say 128 or 256 bytes.
then you extract one line from buffer looking for \r.
with the length of this line + 2 (\r\n) you use SEEK
to position to the beginning of the next line.
then again extract one line, again use SEEK a.s.o.
SEEK you can use from the beginning of the file or from
the current file-pointer position.
To use it from the beginning of the file you have to add
each line-length + 2 in a variable, and use this variable
with SEEK.

hope this helps
 
You may use a istream and use the "fstream ::getline( char* pch, int nCount, char delim = '\n' )" function.
Ex.:
fstream in("filename.txt",ios::in );
in.getline(buf,90,'\n');
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top