//程序片段意图:判断程序目录下是否存在input.txt文件,若不存在,则提示输入文件路径
//错误:函数调用出错input _ error(input) 中“input”被划出,提示调用函数是已删除函数 ==
int input_error(fstream i){
if (!i){
cerr << endl << "Fail to open the file!" << endl << endl;
return -1;
}
else
return 0;
}
int main(){
int n;
fstream input("input.txt");
if (input_error(input) == -1){
fstream input;
string filename;
cout << "Please input the absolute path of the file:";
getline(cin, filename, '\n');
input.open(filename);
if (input_error(input) == -1)return -1;
};
以下为源代码,希望能够得到各位大神的解决,谢谢!
#include<iostream>
#include <iomanip>
#include<fstream>
#include<string>
using namespace std;
long long Fibo[90] = { 0 };
unsigned long long fibo(long n){
if (n <= 1)
return Fibo[n] = n;
else if
(Fibo[n] != 0) return Fibo[n];
else
return Fibo[n] = fibo(n - 1) + fibo(n - 2);
}
int input_error(fstream i){
if (!i){
cerr << endl << "Fail to open the file!" << endl << endl;
return -1;
}
else
return 0;
}
int main(){
int n;
fstream input("input.txt");
if (input_error(input) == -1){
fstream input;
string filename;
cout << "Please input the absolute path of the file:";
getline(cin, filename, '\n');
input.open(filename);
if (input_error(input) == -1)return -1;
};
input >> n;
input.close();
if (n<0 || n>90){
cout << endl << "The integer is illegal!" << endl << endl;
return -1;
}
else
cout << endl << "n: " << n << endl;
cout << endl << "Result: " << fibo(n) << endl;
cout << endl << "—————Process—————" << endl;
for (int i = 0; i <= n; i++){
cout << setw(2) << setfill('0') << i << ".....";
cout << setw(19) << setfill('.') << Fibo[i] << endl;
}
cout << endl;
return 0;
}
再次感谢!
//:~