Is it possible to pass a map container to the copy algorithm and display it to the std::cout? If so how?
What I tried below doesn't work but it looks like it should. Any comments or pointers will be appreciated.
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <iterator>
std::ostream& operator<<(std::ostream & out, const std::pair<std::string, unsigned long> & p)
{
return out << p.first << " " << p.second;
}
int main(int argc, char**argv)
{
std::map<std::string, unsigned long> the_words;
for (int i = 1; i < argc; ++i)
++the_words[argv[i]];
std::map<std::string, unsigned long>::const_iterator begin = the_words.begin();
std::cout << *begin << std::endl;
//copy(the_words.begin(), the_words.end(), std::ostream_iterator< std::pair<std::string, unsigned long> >(std::cout, "\n"));
return 0;
}