thomas wrote:
> The file "filename" should be formated as "int int string" for each
> line,
> but the last line may have only "int int" or even "int".
> So the program encounter error when reading the last line.
>
> It's supposed that I can remove the last line if it's mal-formated.
> But the file is huge, opening it is time consuming.
>
> Is there a convenient way to tell "istream" that " this line is not
> formated as expected, you can stop here"?
I haven't tried this snippet, but something like this might work
std::ifstream input("yourfile");
std::string line;
while(std::getline(input,line)) {
std::istringstream inline(line);
int i1, i2;
std::string s3;
if(!(inline >> i1 >> i2 >> s3)) {
// bad line
break;
}
// continue processing line
}
LR