Answer the question
In order to leave comments, you need to log in
How to open a file correctly using try, catch, throw or how to make the program work correctly?
ifstream fin;
fin.exceptions(std::ios::badbit | std::ios::failbit);
try {
cout<<"Открытие файла..."<<endl;
fin.open("E:\\product.txt");
cout<<"Файл успешно открыт!"<<endl;
}
catch(const exception & ex)
{
cout<<ex.what()<<endl;
cout<<"Ошибка открытия файла!"<<endl;
}
while(!fin.eof()){
line = "";
getline(fin, line);
cout<<line<<endl;
}
fin.close();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question