贤瀚宸 2019-06-17 16:49 采纳率: 0%
浏览 5043

c++读写出现问题 没有与参数列表匹配的 重载函数

图片说明
我这个是商品销售管理系统,我把输入的信息全部存进文件里,读取有问题

#include <iostream>
#include <string>
#include <fstream> 
#include <iomanip>
#include <cstdlib>
using namespace std;

class Date
{
public:
    Date() {}
    Date(int y, int m, int d) :year(y), month(m), day(d) {}
    Date(Date &a) {
        year = a.year; month = a.month;  day = a.day;
    }
    void show() {
        cout << year << "年" << month << "月" << day << "日" << endl;
    }
protected:
    int year, month, day;
};
class Goods :public Date
{
private:
    int id;
    int price;
    int count;
    int number;
    string name;
    string type;
    int size = 0;
    //char buf[500];
    //Date pubdate;
public:
    Goods();
    Goods(int i, string n, string t, int p, int c, int y, int m, int d) ;
    Goods(Goods &b);
    void menu();
    void buy();
    void search();
    void display();
};
Goods buf[500];
Goods::Goods() {}
Goods::Goods(int i, string n, string t, int p, int c, int y, int m, int d) :Date(y, m, d) {
    id = i; name = n; type = t; price = p; count = c;
}
Goods::Goods(Goods &b)     
{
    id = b.id; name = b.name; type = b.type; price = b.price; count = b.count;
}
void Goods::menu() {
    cout << "           商品管理系统      " << endl << endl;
    cout << "      ******1.进购商品*******" << endl << endl;
    cout << "      ******2.查询库存*******" << endl << endl;
    cout << "      ******3.购买商品*******" << endl << endl;
    cout << "      ******4.查询销售记录***" << endl << endl;
    cout << "      ******0.退出***" << endl << endl;
    cout << "请选择服务项目:";
    int choose;
    cin >> choose;
    switch (choose)
    {
    case 1:buy(); break;
    case 2:search(); break;
        //case 3:sell(); break;
        //case 4:search(); break;
    case 0: {
        cout << "**********谢谢使用**********" << endl;
        return;
    }
            break;
    }
}
void Goods::buy() {
    char ch;
    cout << "进购种类:";
    cin >> number;
    ofstream fout("G:\\abc\\商品销售管理.txt", ios_base::app);
    //fout << "商品编号     " << "商品名称     " << "商品型号     " << "商品数量     " << "商品价格     " << "进购日期" << endl;
    for (int i = 1; i <= number; i++) {
        cout << "商品编号(如:1001):";
        cin >> buf[size].id;
        cout << "商品名称:";
        cin >> buf[size].name;
        cout << "商品型号:";
        cin >> buf[size].type;
        cout << "商品数量:";
        cin >> buf[size].count;
        cout << "商品价格:";
        cin >> buf[size].price;
        cout << "进购日期:";
        cin >> year >> month >> day;
        cout << endl;
        size++;
        fout << id << setw(14) << name << setw(14) << type << setw(12) << count << setw(13) << price << setw(12) << year << "年" << month << "月" << day << "日" << endl;
    }
    cout << "是否继续进购?(是Y/否N): ";
    cin >> ch;
    if (ch == 'Y' || ch == 'y') {
        buy();
    }
    if (ch == 'N' || ch == 'n') {
        menu();
    }
}
void Goods::search() {
    int n, i;
    ifstream ifs("G:\\abc\\商品销售管理.txt");
    while (!ifs.eof()) {
        ifs.getline(buf, 500, '\n');
        //cout << buf << endl;
        cout << "请输入您要查询商品编号:";
        cin >> n;
        for (i = 0; i <= size; i++) {
            if (buf[i].id == n) {
                buf[i].display();
            }
        }
        cout << sizeof(buf) << endl;

    }

    ifs.close();
    int main()
{
    Goods good;
    good.menu();
    system("pause");
    return 0;
}
  • 写回答

1条回答

  • BuXianShan 2019-06-17 17:08
    关注

    ifs.close()后面少个“}”,你可以发一下“商品销售管理.txt”文件的内容吗?

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器