I have a map having strings as keys and lists of file names as values.
ex: Map(firstDir, list(file1,file2,file3))
I know that by using following code I can print value which is of String
{
cout << "Key: " << pos->first << endl;
cout << "Value:" << pos->second << endl;
}
But if pos->second
contains a List, how to display?
overload operator <<
for list
std::ostream& operator << (std::ostream& out, std::list<ListElemType> const& lst)
{
for(std::list<ListElemType>::iterator it = lst.begin(); it != lst.end(); ++it)
{
if(it != lst.begin())
out << /*your delimiter*/;
out << *it;
}
return out;
}
now you can do what you want
cout << "Key: " << pos->first << endl << "Value:" << pos->second << endl;
How about using Boost.Foreach ?
#include <boost/foreach.hpp>
{
cout << "Key: " << pos->first << endl;
cout << "Values:" << endl;
BOOST_FOREACH(std::string const& file, pos->second)
{
cout << "\t" << file << endl;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With