I have the following:
Is there a way to implement a loop to input the data sets? I have tried using the iterator as a loop counter but i end up with various errors. i guess that is not allowed.Code:#include <cstdlib> #include <iostream> #include <map> using namespace std; int main(int argc, char *argv[]) { map <int, char> mp; map<int, char> :: iterator it; mp.insert(map <int, char> :: value_type(1,'A')); //storing in sorted order -> A,B,C,D,E mp.insert(map <int, char> :: value_type(3,'C')); mp.insert(map <int, char> :: value_type(2,'B')); mp.insert(map <int, char> :: value_type(5,'E')); mp.insert(map <int, char> :: value_type(4,'D')); it = mp.begin(); while(it != mp.end()){ cout << (*it).first <<" "; // prints key cout << (*it).second << endl; //print data it++; } system("PAUSE"); return EXIT_SUCCESS; }



LinkBack URL
About LinkBacks



