list 迭代器的用法
string strTemp; list<string> strList; char *ch = new char[512]; strcpy( ch , "1234567890"); strTemp = ch; strList.push_back( strTemp ); char *p = "abcdefg"; strTemp = p; strTemp += strTemp; char *lp = "e:\Project\InfoStation\INFOSTATION05-20.1\OUTPUT\Picture\热烈欢迎01.bmp"; strList.push_back( lp); strList.push_back( strTemp ); strTemp = "1"; strList.push_back( strTemp ); char chTep[512]; strcpy( chTep , "wo bu houhui"); strTemp = chTep; strList.push_back( strTemp ); //迭代器的用法来了 list<string>::iterator it; for ( it = strList.begin(); it != strList.end(); it++ ) { if( *it == "1") { strList.erase( it ); break; } } //因为删除了一个数据,容器里面的数据就不连续了,这时迭代器就失效了,想要再次循环操作,重新继续迭代器 for ( it = strList.begin(); it != strList.end(); it++ ) { cout<<*it<<endl; }