-
Please Some Advice?
Hey guys If I want to just read the last line of a txt file and display it how could I do that?
for example if I want to read the whole file with this info but I need to cout just the last line ?
"N2014776582","M0210400060667804600_3","https://extpws09.chubb.com/eLossDirect/eLossFaxEDI.asp?route=east","0","03/07/06 14:41:51","03/07/06 14:51:46","M0210400060667804600","00001","CS-FNOL","LIAB","00000","005","00742","S","SUCCESS"
"N2014776582","M0210401060607750200","FNOL.ATTACH. [email protected]","0","03/01/06 14:32:29","03/01/06 14:36:59","M0210401060607750200","00001","CS-FNOL","NONFORM","00000","000","00002","1001","Non-Recognizable Form"
I would appreciate some suggestions thank you
-
by the way the file is going to change once in a while so how could I create a loop that will run until the last line and display it ?
-
Maybe something along this line.
Code:
#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::ifstream file("file.txt");
std::string line, last;
while ( getline(file, line) )
{
if ( line != "" )
{
last = line;
}
}
std::cout << "This is the last line of the file:\n"
<< last << '\n';
return 0;
}
-