STL中map 和vector嵌套使用示例

 

暂且只有添加和循环输出,后期再加以改进。

 

 

 #pragma warning(disable : 4786 ) #include #include #include #include #include using namespace std; typedef map STRING2STRING; typedef std::map > STRING2VECTOR; int main() { std::map map_test; map_test.insert(STRING2STRING::value_type("2001", "test1")); map_test.insert(STRING2STRING::value_type("2002", "test2")); map_test.insert(STRING2STRING::value_type("2003", "test3")); map_test.insert(STRING2STRING::value_type("2004", "test4")); map_test.insert(STRING2STRING::value_type("2005", "test5")); map::const_iterator map_conitor = map_test.begin(); for(; map_conitor!= map_test.end(); map_conitor++) { cout<first<<" "<second< vec1; vec1.push_back("test1_vector1"); vec1.push_back("test1_vector2"); vec1.push_back("test1_vector3"); vec1.push_back("test1_vector4"); std::vector vec2; vec2.push_back("test2_vector1"); vec2.push_back("test2_vector2"); vec2.push_back("test2_vector3"); vec2.push_back("test2_vector4"); std::map > testMap; testMap.insert(STRING2VECTOR::value_type("10001",vec1)); testMap.insert(STRING2VECTOR::value_type("10002",vec2)); std::map >::iterator map_it = testMap.begin(); for ( ; map_it != testMap.end(); map_it++) { cout<first<<"/t"; vector::iterator mapvec_itor = map_it->second.begin(); for ( ; mapvec_itor != map_it->second.end(); mapvec_itor++) { cout<<(*mapvec_itor)<<" "; } cout< >::iterator iter=testMap.find( "10002" ); if(iter!=testMap.end()) //should like this { vector::iterator it = iter->second.begin(); while(it != iter->second.end()) { cout<<(*it++)<

你可能感兴趣的:(win32,SDK,STL&BOOST)