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

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

//程序片段意图:判断程序目录下是否存在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 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题