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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:25:34+00:00 2026-06-06T11:25:34+00:00

How to modify the vlaue of a key-value Pair from a map while I

  • 0

How to modify the vlaue of a key-value Pair from a map while I do not know whether the key is exist in the map?

for example , there is a key-value pair in a map:

a[5]   =    " H ";

// But after some operation,like insert, erase etc ; I do not know whether 5 still exist in the map,can I modify it like this ?:

a[5]   =   " G ";

// or I must define a iteraotr pos

pos = my_map.find(5);
if( pos !=  my_map.end())
{
 pos->second   =   " G ";
}

Is there any other way I can modify a value of a key-value Pair from a map??? Thanks!!!

  • 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-06-06T11:25:36+00:00Added an answer on June 6, 2026 at 11:25 am

    The standard map has the curious property that indexing into an element that is not present in the map causes an association to be created between that key and a default constructed value. So, if the element 5 is not present as a key in the map, after you do a[5] it will exist and be associated to an empty string.

    C++11 added a new at method that throws if the key does not exist in the map, which makes it possible to index into a const map.

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

Sidebar

Related Questions

I'm talking about operators which not return a value but modify (overwrite) the first
So I need to modify the array in a memcached key-value pair. I need
From http://fullthrottledevelopment.com/php-nonce-library#download , there is a PHP nonce library, but there are a few
Seeking suggestions from PHP architects! I'm not terribly familiar with PHP but have taken
Is there a way in which I can modify the value of one of
so I am trying to modify an array by adding key and value in
Given std::map<int,std::string> myMap; fillMyMapWithStuff(myMap); // modify key values - I need to add a
When we want to modify some value in one object we may use two
Can I create an attribute that will let me modify the value of it
i declare a global variable and use and modify its value in the function.

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.