CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009
    Posts
    161

    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

  2. #2
    Join Date
    Jul 2005
    Posts
    266

    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.

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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)
    {
    }
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured