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

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”文件的内容吗?

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮