c++数据写入问题。祝大家的父母身体健康!

来源:百度知道 编辑:UC知道 时间:2024/06/25 19:33:25
数据写入不会了,请指教!
#include<iostream>
#include<fstream>
#include"Goods.h"
using namespace std;

class GWriteFile
{
public:
void WriteDate(CGoods &);
ofstream H_WriteFile;
};

void GWriteFile::WriteDate(CGoods &hw)
{
H_WriteFile.open("InGoods.txt");
H_WriteFile<<hw.GoodsName<<" "<<hw.GoodsNumber<<" "<<hw.GoodsType<<" "<<hw.GoodsSource_Address<<" "<<hw.GoodsInPrice<<" "<<hw.GoodsInAmount<<" "<<hw.GoodsInDate;
H_WriteFile<<'\n';
H_WriteFile.close();
}
————————————————————————
提示错误:
writefile.cpp
E:\c++练习程序\进销存管理系统\jxc\writefile.cpp(16) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class Date' (or ther

你检查一下你的CGoods类的定义,是不是少了hw.GoodsInDate;
或者成员数据hw.GoodsInDate是个自定义类型,而不是(int,string,等),
如果是一个自定义类型,那么就一定要对它定义operator<<;怎么定义,我觉得你应该知道。

错误提示里说的很明显啊,你直接把一个Data的对象输出了,但并没有重载运算符,要不就是重载Data的<<运算符,要么就是把Data的基本类型的数据成员逐个输出

根据提示的错误来看,可能是类CGoods的某个属性不能直接通过标准输出'<<'的方式进行输出:应该是有个属性是Date类的造成这个错误,从名字上来看,最有可能的是hw.GoodsInDate。