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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:19:53+00:00 2026-05-25T16:19:53+00:00

Is it a feature of unordered_map::find() to insert the key that we lookup with

  • 0

Is it a feature of unordered_map::find() to insert the key that we lookup with 0 value automatically?
Let me make this clear

    unordered_map<int, int> tempMap;
    //some code
    if(tempMap.find(1) == tempMap.end()){
      //do something but not insert the 1 with a corresponding value into the tempMap
    }

so if I lookup 1 again, will it be there in the tempMap having 0 as corresponding value.
Is that a feature of unordered_map?

  • 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-25T16:19:54+00:00Added an answer on May 25, 2026 at 4:19 pm

    No, find only searches and returns an iterator.

    That said, std::unordered_map (and std::map) both overload operator[] which will insert a default if needed:

    // if element with a key value one exists, return that. otherwise, insert
    // a default initialized element (zero in this case), and return that
    auto& val = tempMap[1]; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any feature in IIS 7 that automatically deletes the logs files older
We have this default feature in android 3.0 that when we long press somewhere
Anyone know this compiler feature? It seems GCC support that. How does it work?
This feature worked a bit, then stopped working. Background: Given a user is logged
My app needs feature to open iPhone/iPad Mail, contacts, Calendars settings panel and automatically
This is the feature i want to implement: check a tree node by click
In simplistic terms, a feature structure is an unordered list of attribute-value pairs. [number:sg,
A feature in Reddit that I like is the ajax login - you enter
A less well-known feature of JavaScript is that you can use labels to break
I really loved this feature when I used Eclipse for Java programming, but I

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.