|
-
January 18th, 2010, 03:00 AM
#1
show alle the pairs of a hash <map>
Hi,
I have an associative array made up like the following:
Code:
map<string, string> hash;
I'd like to use a for() to show all the pairs...how can I do that?
thanks
-
January 18th, 2010, 05:22 AM
#2
Re: show alle the pairs of a hash <map>
map<string, string>::iterator iter;
for(iter = map.begin();iter!=map.end();++iter)
print(iter->first,iter->second);
where print is your own printing function.
-
January 18th, 2010, 06:45 AM
#3
Re: show alle the pairs of a hash <map>
For all STL all containers, there are iterators (or constant iterators) defined that you can access like this (m is a variable of type map<string, string>):
Code:
for(std::map<string, string>::iterator it = m.begin(); it!=m.end(); ++it)
{
}
Code:
for(std::map<string, string>::const_iterator it = m.begin(); it!=m.end(); ++it)
{
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|