C++ - Print Out Objects From Set
- by John Smith
If I have a C++ set, declaration
set personList;
with iterator,
set::const_iterator location;
how can I print out the contents of the set? They are all person objects, and I have overridden the operator<< for Person.
The line that errors is:
cout << location
and it's in a basic for loop.
Netbeans gives the following error:
proj.cpp:78: error: no match for ‘operator<<’ in ‘std::cout << location’
so it looks like it wants an override for the iterator's <<.
Basically, I am taking objects that used to be stored in an array format, but are now in a set. What is the equivalent to cout << array[i] for sets?