You'll need to overload operator<<
for AccDetails
. It is what ostream_iterator
calls internaly.
Something like this:
std::ostream& operator<<(std::ostream& stream, const AccDetails& obj)
{
// insert objects fields in the stream one by one along with some
// description and formatting:
stream << "User Name: " << obj.username << '\n'
<< "Real Name: " << obj.name << '\n'
<< obj.topicid << ' ' << obj.testid << '\n';
return stream;
}
The operator takes the stream it inserts to as first parameter and a constant reference to the object it is streaming as the second one (this allows passing temporary AccDetails
, too). Now you can also say:
AccDetails acc;
std::cout << acc;
If the operator would need access to AccDetail
's private fields, you would need to declare as a friend
.
If you're new to operator overloading, I suggest you read this SO thread.
Hope that helps.