【发布时间】:2016-11-16 04:58:15
【问题描述】:
如何提示用户输入输出文件名和IF not found 重试?
每次发生这种情况时,它都会创建输出文件;我不希望我只希望它读取输出文件。
do{
cout <<"Type the name of the output file which will hold the simulation results:\n";
cin >> nameoutputfile;
fileout.open(nameoutputfile);
if (fileout.fail())
{
cout << "ERROR: File "<< nameoutputfile <<" could not be opened\n";
tries[1]++;
}
if (tries[1] == trylimit)
{
cout << "ERROR: You exceeded maximum number of tries allowed\n";
cout << "while entering the input file name";
return 2;
}
}while(fileout.fail());
这就是输出应该是什么
outputReadOnly.txt
ERROR: File outputReadOnly.txt could not be opened
Type the name of the output file which will hold the simulation results:
outputReadOnly.txt
ERROR: File outputReadOnly.txt could not be opened
Type the name of the output file which will hold the simulation results:
outputReadOnlyt.txt
ERROR: You exceeded maximum number of tries allowed
while entering the output file name
【问题讨论】:
-
你的文件输出对象是什么类型的?
-
文件可以是任何东西,但必须存在
-
我的意思是你如何初始化变量?
标签: c++ visual-studio c++11