§outh§tar
04-27-04, 08:13 PM
How do I overload the output stream operator for structures. I have this code but it only gives me an error. I know this is relatively simple, but please bear with me. :(
struct item
{
int id;
int inv;
apstring productName;
};
struct storeType
{
apvector <item> list;
int number;
};
ostream& operator<<(ostream& osObject, const storeType& object)
{
int x=0;
for (x=0; x<50; x++)
osObject << object.list[x].id << " " << object.list[x].inv << " " << object.list[x].productName << endl;
//Return the ostream object
return osObject;
}
Can anyone please tell me why this doesn't work when I try to output it. I am not allowed to use any other way but overloading the output stream so I'm stuck trying to figure this out:
void loadData(storeType &items)
{
cout << items; // I get the error here!
}
struct item
{
int id;
int inv;
apstring productName;
};
struct storeType
{
apvector <item> list;
int number;
};
ostream& operator<<(ostream& osObject, const storeType& object)
{
int x=0;
for (x=0; x<50; x++)
osObject << object.list[x].id << " " << object.list[x].inv << " " << object.list[x].productName << endl;
//Return the ostream object
return osObject;
}
Can anyone please tell me why this doesn't work when I try to output it. I am not allowed to use any other way but overloading the output stream so I'm stuck trying to figure this out:
void loadData(storeType &items)
{
cout << items; // I get the error here!
}