"thomas" <> wrote in message
news:5a901f5a-4d58-4e95-9cff-...
>a question about map iterator
>
> ---code---
> #include<map>
> #include<iterator>
> using namespace std;
>
> int main(){
> map<string,int> mp;
> mp.insert(pair<string,int>("hello",1));
> for(map<string,int>::iterator it(mp.begin()); it<mp.end(); it+
> +) ///----L---
> cout<<it->first<<endl;
> }
> ----code ----
>
> it cannot compile; if I change the "it<mp.end()" to "it!=mp.end()"
> in line L , it works.
>
> for int vectors, I can use "it<vi.end()" to make boundary check, but
> for map it doesn't works.
>
> any explaination or suggestions?
You've already gotten the explanation. The suggestion is instead of using <
use !=
for(map<string,int>::iterator it(mp.begin()); it != mp.end(); ++it) {
cout<<it->first<<endl;
}
|