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

  • SEARCH
  • Home
  • 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 3627590
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:54:28+00:00 2026-05-18T23:54:28+00:00

I have declared an associative array and now want to print it: #include <map>

  • 0

I have declared an associative array and now want to print it:

#include <map>
#include <string>
#include <cstdio>

using namespace std;

int main() {
    map<string, int> m;

    m["Peter"] = 4;
    m["John"] = 3;
    m["Katie"] = 3;

    map<string, int>::iterator curr,end;

    for(curr = m.begin(), end = m.end(); curr != end; curr++) {
        printf("%s : %i\n", curr->first, curr->second);
    }
    return 0;
}

I’m getting an error from my compiler:

main.cpp: In function ‘int main()’:
main.cpp:24: warning: cannot pass objects of non-POD type ‘const struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >’ through ‘...’; call will abort at runtime

And surprise suprise – it’s true – call aborts at runtime…

But I don’t know why… What should I fix? What exactly mean “through ‘…’” ?

  • 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-18T23:54:28+00:00Added an answer on May 18, 2026 at 11:54 pm

    try:

        printf("%s : %i\n", curr->first.c_str(),  curr->second);
    

    The c_str() method convert std::string to a c-style string (char*).

    the ... refers to printf‘s vararg prototype:

    int printf(const char *format, ...);
    

    which won’t support passing c++ objects.


    BTW, you should use ++curr instead of curr++. This is some c++ magic that prevent duplicating a reference.

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

Sidebar

Related Questions

In my C# source code I may have declared integers as: int i =
I have a COM object written using the MS ATL library. I have declared
If 'Associative Array variable' is declared globally , able to use that in OPEN
I have declared a DataGrid in UserControl. Now I have included the UserControl in
I have declared some string properties on the app delegate for the purpose of
This is a contrived example, but lets say I have declared objects: CustomObj fooObj;
I have two classes declared like this: class Object1 { protected ulong guid; protected
I have the following enum declared: public enum TransactionTypeCode { Shipment = 'S', Receipt
We have our domain model declared in rusty old hbm files, we wish to
I have a boolean variable declared at the top of a class and when

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.