S
sam
In the following program I am getting an error when I am trying to access
i1.first. Is this valid statement?
how can I access map value through iterator? Please help me foreach
function also.
void printall(string str, int i){
cout << str<<endl;
}
int main(){
map<string,int> m;
m["One"]=1;
m["Two"]=2;
m["Three"]=3;
map<string,int>::iterator i1;
i1= m.begin();
while(i1!=m.end()){
cout << i1.first; // Here is the problem.
++i1;
}
//foreach(i1.begin(),i1.end(),printall);
}
i1.first. Is this valid statement?
how can I access map value through iterator? Please help me foreach
function also.
void printall(string str, int i){
cout << str<<endl;
}
int main(){
map<string,int> m;
m["One"]=1;
m["Two"]=2;
m["Three"]=3;
map<string,int>::iterator i1;
i1= m.begin();
while(i1!=m.end()){
cout << i1.first; // Here is the problem.
++i1;
}
//foreach(i1.begin(),i1.end(),printall);
}