theusProme 2015-10-11 15:06 采纳率: 0%
浏览 4258

错误提示:它是已删除的函数,求解答,谢谢!

//程序片段意图:判断程序目录下是否存在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;
} 

再次感谢!
//:~

  • 写回答

2条回答 默认 最新

  • theusProme 2015-10-11 15:07
    关注
    /*Fibonacci 1410729 许木胜 */
    #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;
    } 
    

    以上才是源代码,第一次提问,错误请原谅= =

    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB yalmip 可转移负荷的简单建模出错,如何解决?
  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?