c++ - C++ 创建一个函数来读取 .txt 文件并检查以确保文件存在,但我的循环不起作用
问题描述
我正在尝试创建一个函数来读取文件,检查以确保它存在(如果它不再要求文件名),然后打印“正在加载...”如果它确实找到了文件。
但是,循环只经过一次。它打印出“文件错误:文件不存在!” 然后结束程序。有任何想法吗?如果您需要更多信息,请告诉我!
void find_board(string fileName)
{
bool filefound = 0;
ifstream in_stream;
do
{
cout << "Enter the name of the file containing the board: ";
cin >> fileName;
in_stream.open(fileName.c_str());
if (in_stream.fail())
{
filefound = 0;
cout << "FILE ERROR: File does not exist!" << endl;
exit (EXIT_FAILURE);
}
else
{
filefound = 1;
}
} while (filefound == 0);
cout << endl << "Loading..." << endl;
return;
}
解决方案
是exit (EXIT_FAILURE);
为了什么?
推荐阅读
- reactjs - React Dnd useDrag 无法正常工作?
- javascript - 显示未定义变量的问题未显示
- javascript - 为什么组件没有在 react js 中呈现?
- python - 如何删除除 OS X 携带的版本之外的所有其他 python 版本
- python - 如何解决此问题: ConnectionAbortedError: [WinError 10053] 已建立的连接已被主机中的软件中止
- wso2-am - 如何在 WSO2 APIM 3.0.0 中禁用 SSL?
- c# - 我想通过手动输入和复制粘贴解决 Teams 中的消息响应之间的差异
- npm - 我们可以以角度延迟加载包吗,我只能在单击某个按钮时下载所需的包吗?
- python - Openpyxl:TypeError - 将几列连接成每行一个单元格
- c++ - 如何在子类中使用 SFINAE