Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6011389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:15:11+00:00 2026-05-23T02:15:11+00:00

for debugging I need to dump the contents of nested maps. I tried to

  • 0

for debugging I need to dump the contents of nested maps. I tried to describe this in the following code:

struct Foo
{       
   string name;
};

typedef std::map<string, Foo> MapFoo;

struct Bar  {
  string name;    
  MapFoo mapFoo;
};

typedef std::map<string, Bar> MapBar;

...

MapBar mapBar = init_mapBar(); 

const MapBar::const_iterator it = mapBar.find("name");

if ( mapBar.end() != it )
{
    return it->second;
}

Before I return it->second, I want to dump the contents of that item to cout. I am getting lost with the iterators when trying doing this. Thank you very much for some help or hints.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:15:12+00:00Added an answer on May 23, 2026 at 2:15 am

    Write a function:

    template <typename K, typename V, typename C>
    void Dump( const map <K,V,C> & m ) {
        typename map <K,V,C>::const_iterator it = m.begin();
        while( it != m.end() ) {
            cout << it->first << " = " << it->second << endl;
            ++it;
        }
    }
    

    You can then say:

    if ( mapBar.end() != it )
    {
        Dump( it->second );
        return it->second;
    }
    

    and use it for dumping any other maps where K & V are types that have streaming operators available.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help debugging this error Expected Identifier . The code is - +(NSString
I need this for debugging purposes and need to dump all variables. Is there
I need to see the contents of a std::map variable while debugging. However, if
I need to print some structure for debugging purposes.Since the code base is huge
For debugging purposes, I need to follow the execution of some piece of code,
I need help on this with some debugging as I am unable to use
I need some advice on debugging the code below please. I'm feeding in Twitter
I am debugging a program in MacOSX, and I need that this program thinks
I need a proxy for web development debugging. Preferably something standalone so I can
I need recommendations for good application servers for monitoring and debugging PHP and Mysql

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.