stl中 MAP怎么用copy以迭代的方式输出

89 阅读1分钟

#include

#include

#include

#include

#include

typedef std::map<int,std::string> map_test;

typedef std::pair<int,std::string> pair_test;

typedef std::ostream_iterator<pair_test> ostream_itor;

namespace std

{

std::ostream& operator<<( std::ostream& os, const pair_test& obj )

{

    return os << obj.first << ", " << obj.second;
    
}

}

using namespace std;

int main()

{

map_test te;

for( size_t i=0; i<5; ++i )

    te.insert( make_pair(i,"abc") );
    

copy( te.begin(), te.end(), ostream_itor(cout,"\n") );


return 0;

}