- 论坛徽章:
- 0
|
请教迭代器的一个问题!
- #include <iostream>;
- #include <map>;
- using namespace std;
- struct stat_get
- {
- stat_get():sum(0.0),count(0){}
- float sum;
- int count;
- };
- typedef map <string,stat_get>; Data;
- typedef map <string,stat_get>;::const_iterator DataIt;
- void print_data( const Data &stats )
- {
-
- for( DataIt p = stats.begin(); p!=stats.end(); p++ )
- {
- cout<<(*p).first<<'\n'<<"sum is "<<(*p).second.sum<<'\n';
- }
- }
- int main ( int argc, char *argv[] )
- {
- Data m;
- stat_get s;
- m["hello"] = s;
-
- print_data ( m );
- return 0;
- }
复制代码 |
|