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

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

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

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

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP