A
Amadeus W. M.
I'm trying to read a vector from a file, while checking the correctness of
the input. I do this by setting the failbit.
double tmp;
vector<double> x;
fstream IN(argv[1], ios::in);
IN.exceptions(std::ios_base::failbit);
try{
while(IN>>tmp)
x.push_back(tmp);
}
catch(...){
}
But that's not right, because when IN reads the EOF an exception is raised.
I only want to catch the potential input errors other than the EOF.
What's the right way to do this?
Thanks.
the input. I do this by setting the failbit.
double tmp;
vector<double> x;
fstream IN(argv[1], ios::in);
IN.exceptions(std::ios_base::failbit);
try{
while(IN>>tmp)
x.push_back(tmp);
}
catch(...){
}
But that's not right, because when IN reads the EOF an exception is raised.
I only want to catch the potential input errors other than the EOF.
What's the right way to do this?
Thanks.