贤瀚宸 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 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块
  • ¥15 nhanes加权logistic回归,svyglm函数