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 7057255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:57:51+00:00 2026-05-28T03:57:51+00:00

map <int, string> rollCallRegister; map <int, string> :: iterator rollCallRegisterIter; pair <map <int, string>

  • 0
map <int, string> rollCallRegister;
map <int, string> :: iterator rollCallRegisterIter;

pair <map <int, string> , bool> returnPair;

rollCallRegister.insert (pair <int, string> (1, "anisha"));

In this code, pair <map <int, string> , bool> returnPair; means that this pair takes a map row as the first value and a bool as the second.

Question:
How to insert bool here: rollCallRegister.insert (pair <int, string> (1, "anisha"));?

Secondly, pair <map <int, string> :: iterator, bool> returnPair; This pair takes an iterator of map as the first input.

Question:
How is this different from the previous pair syntax, since the insertion way is still the same: rollCallRegister.insert (pair <int, string> (1, "anisha"));?

  • 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-28T03:57:51+00:00Added an answer on May 28, 2026 at 3:57 am

    The first value of a pair<map<int, string >, bool> is not a map row, it is an entire map (so probably not what you are looking for). The second pair, on the other hand, associates a map entry to a boolean value.

    Regarding the insertion, I don’t really get your question: in both samples, you are inserting into a map<int, string>; it has nothing to do with the different types of pairs you define. To create instances of these two kind of pairs, you need a map in the first case, and an iterator in the second:

    pair<map<string, int>, bool> p1(rollCallRegister, true);
    pair<map<string, int>::iterator, bool> p2(rollCallRegisterIter, false);
    

    Edit:

    Based on the comments you made on your question, I think you confuse the content of the map (pair<string, int>) and the value returned by insert (pair<map<string, int>::iterator, bool>).

    When you declare a map<K,V>, its content is stored in pair<K,V>. Therefore, to insert a new entry in this map, you need to create a pair containing the key and the value you want to insert:

    map<K,V> myMap;
    pair<K,V> myEntry(key, value); // entry to insert
    
    myMap.insert(myEntry);         //or you can create the entry on-the-fly
    myMap.insert(make_pair(key, value));
    

    Now, when you insert an entry into a map, there is a possibility that the key was already present. If this is the case, then the insertion should “failed”: after the call to insert, the key is still associated with the former value. However, the caller should be warned that he tried to insert an entry with a key that already existed in the map.

    This is achieved by having insert return a pair<map<K,V>::iterator, bool>, where the second value of this pair is a boolean indicating whether the insertion occurred (the key was not already present in the map) or not. The first value is an iterator to the entry corresponding to the key. This entry contains the key and its associated value (either the one you just inserted, or the one that was already there).

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

Sidebar

Related Questions

This is my code map<string,int> persons; persons[B] = 123; persons[A] = 321; for(map<string,int>::iterator i
map <int, string> rollCallRegister; map <int, string> :: iterator rollCallRegisterIter; map <int, string> ::
I'm trying to turn this C++ code/answer (class that creates map string <-> some_array_of_predefined_function_types
std::map<std::string, int> m; // Can I make assumption that m[NoSuchKey] will return 0? std::cout
I'd like to copy values that match a predicate (equal ints) from a map<string,int>
in my function, i have this parameter: map<string,int> *&itemList I want to first check
I am initializing a map map<string,int> ex; in C++. I could not find contains_key
If i have a stl map from string to int and i want to
Let's say I have two maps: typedef int Id; std::map<Id, std::string> idToStringMap; std::map<Id, double>
using namespace std; class A { public: A() {} ~A() {} map<int, string*>& getMap()

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.