Now I have a txt file like this:
5
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
5
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
...
One loop of this file is 7 lines, and the second line of the 7 lines is a blank line. My file has a total of 5 loops , but when my code is set to read 10 loops, the code will not report an error, how should I modify the code to report an error at the end of the file, pay attention to my text file a blank line appears.
#include<fstream>
#include<string>
int main()
{
std::ifstream get_in("tst.txt", std::ios :: in );
for ( int loop=0;loop<10;loop++ )
{
std::string line;
for ( int i=0;i<7;i++ )
{
getline(get_in, line);
}
}
return 0;
}
This is a simplified example of my code, I want it to error out when the text is not enough for the number of rows I want to read, instead of running normally.