how to get a line of text file
-
Ive managed to read a whole text file into a string. The text file has 200 lines. I wanna read a specific line from the string, how can i do it? I tried getline(); but the problem is that it reads a line rite from the starting position of the string but not from a specific point.
nOmI
-
Ive managed to read a whole text file into a string. The text file has 200 lines. I wanna read a specific line from the string, how can i do it? I tried getline(); but the problem is that it reads a line rite from the starting position of the string but not from a specific point.
nOmI
Well, you may read a line at time or may move a pointer inside the buffer. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Well, you may read a line at time or may move a pointer inside the buffer. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Instead of reading the whole file at once, read it one line at a time until you get to the desired line. Otherwise, you'll need to parse the buffer (a line will by separated by a
\r\n
pair)."Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
-
Ive managed to read a whole text file into a string. The text file has 200 lines. I wanna read a specific line from the string, how can i do it? I tried getline(); but the problem is that it reads a line rite from the starting position of the string but not from a specific point.
nOmI
Did you try with
CFile::Read
? -
Well, you may read a line at time or may move a pointer inside the buffer. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]CPallini wrote:
Well, you may read a line at time or may move a pointer inside the buffer.
And you got 1 vote at time but now you get a pointer of 5. :laugh:
-
CPallini wrote:
Well, you may read a line at time or may move a pointer inside the buffer.
And you got 1 vote at time but now you get a pointer of 5. :laugh:
Thank you, pal. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Instead of reading the whole file at once, read it one line at a time until you get to the desired line. Otherwise, you'll need to parse the buffer (a line will by separated by a
\r\n
pair)."Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
Thank you for elaborating my lazy answer. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Ive managed to read a whole text file into a string. The text file has 200 lines. I wanna read a specific line from the string, how can i do it? I tried getline(); but the problem is that it reads a line rite from the starting position of the string but not from a specific point.
nOmI
This function takes two parameters 1. first one is the path of file to be read. 2. second parametrs is the line number you want to get from the file.
CString GetLine(CString sFileName, int nLineNumber)
{
CStdioFile Inputfile;
CString sLine = _T("");
CFileException FileExc;
UINT nOpenFlags = CFile::modeRead;//OPen the file & load it into a CStdioFile object
if (!Inputfile.Open(sFileName, nOpenFlags, &FileExc)) {
FileExc.ReportError();
return "Error";
}//Reading line by line while(Inputfile.ReadString(sLine) && nCount < nLineNumber){ nCount++; } Inputfile.Close();
return sLine;
} -
Ive managed to read a whole text file into a string. The text file has 200 lines. I wanna read a specific line from the string, how can i do it? I tried getline(); but the problem is that it reads a line rite from the starting position of the string but not from a specific point.
nOmI