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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:41:43+00:00 2026-06-15T11:41:43+00:00

So, I got this: struct People_Info { bool isWorking; std::string name; int age; float

  • 0

So, I got this:

struct People_Info {
  bool isWorking;
  std::string name;
  int age;
  float height;
};
int counter = 0;
int random = urand(1, 4);
std::map<uin64, People_Info> PeopleMap;

Now, a function will get called that will create an entry in the map with this struct that will set some default values:

PeopleMap[counter].isWorking = false;
PeopleMap[counter].name = "Mr";
PeopleMap[counter].age = 1;
PeopleMap[counter].height = 1.60f;
counter++;

Now, that is the function that should make an entry for someone new, but, throughout the script I will remove some entries, so if I got 5 elements, and I remove e.g. the second one, then, I want to edit some variables of everyone in the map:

for(int i = 0; i < 5 ; i++) {
  if(PeopleMap[i] == PeopleMap.end())  // Don't edit map entries that are erased
    continue;

  PeopleMap[i].isWorking = true;
}

Now, for some reason it is still editing all the entries, do I need to use new to make a struct for every entry?

  • 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-15T11:41:44+00:00Added an answer on June 15, 2026 at 11:41 am

    PeopleMap.end() doesn’t return a valid argument, it’s like a ghost node.

    For example, a way to iterate in map could be:

    for(std::map<uin64, People_Info>::iterator it = PeopleMap.begin();it != PeopleMap.end() ;it++)
    

    See, PeobleMap is like a ghost node in the end denotes that you have reach the end.
    In the previous for, if you like to access to map values you could do:

    it->first // uint64
    it->second.isWorking
    

    So, if you use iterators you don’t have to check erased values and you would be able to edit a parameter in each pair in the map (less key)

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

Sidebar

Related Questions

So I've got this. #define MAX_MENU_OPTIONS 1 typedef struct _NEW_MENU_OPTION { char* name; int
I've got this sample code: struct A { int foo() { return 27; }
I got class with template methods that looks at this: struct undefined {}; template<typename
Wow now i know I dont. Lol. I've got my structure like this: struct
I have a struct like this: typedef struct { int a; int b; int
I've got this code, which I don't understand why it doesn't compile: typedef struct
i've got this struct [Serializable] public struct Foo : IConvertible, IXmlSerializable, IComparable, IComparable<Foo> {
I got a structure like this: struct bar { char x; char *y; };
I've got this simple Perl script: #! /usr/bin/perl -w use strict; use Data::Dumper; my
Got this error message while trying to load view: The model item passed into

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.