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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:15:17+00:00 2026-05-15T16:15:17+00:00

I get some strange behavior when inserting values into a map: I always insert

  • 0

I get some strange behavior when inserting values into a map: I always insert at the end of the map, but sometimes the entries get out of order.

If I do a straight forward test, then I get no problems- the numbers are correctly ordered:

map<int,int> testMap;
for(int i = 0; i < 100; ++i)
{
    // everything is ordered correctly here
    testMap.insert(testMap.end(), pair<int,int>(i,i));
}

But when I parse a string and I try to insert the values in the same order as I read them, then things don’t work out that well:

const string INPUT_TWO =
"=VAR STRING1 \"MYSTRING\"\n\
=VAR STRING2 \"EXAMPLE\"\n\
=VAR NUMBER1 12345\n\
=VAR NUMBER2 23456\n\
=VAR DUMMY 1111\n";

const string VAL_STRING = "VAR";

vector<pair<string, string>> parse_fields(const string & input)
{
    map<string, string> fieldsMap;
    vector<pair<string, string>> sequenceFields;
    vector<string> lines = split(input, '\n');
    for(size_t i = 0; i < lines.size(); ++i)
    {
        if(lines[i].find(VAL_STRING)!=string::npos)
        {
            vector<string> vals = split(lines[i], ' ');
            if(vals.size()==3)
            {
                fieldsMap.insert(fieldsMap.end(), pair<string,string>(vals[1], remove_quotes(vals[2])));
                sequenceFields.push_back(pair<string,string>(vals[1], remove_quotes(vals[2])));
            }
        }
    }
    
    // at the end the map looks like:
    // "DUMMY", "1111"
    // "NUMBER1", "12345"
    // "NUMBER2", "23456"
    // "STRING1", "MYSTRING"
    // "STRING2", "EXAMPLE"
    
    // the vector of pairs looks like:
    // "STRING1", "MYSTRING"
    // "STRING2", "EXAMPLE"
    // "NUMBER1", "12345"
    // "NUMBER2", "23456"
    // "DUMMY", "1111"
    
    return sequenceFields;
}

For your reference, I have pasted all the additional code in a pastie.

Does anybody know why this may be happening?

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

    A std::map is an ordered container, this is what allows it the look-up times it has. If you need both the mapping and listing, consider using Boost.MultiIndex.

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

Sidebar

Ask A Question

Stats

  • Questions 501k
  • Answers 501k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use ProcessExplorer to determine what other process is holding the… May 16, 2026 at 2:20 pm
  • Editorial Team
    Editorial Team added an answer Ok, so I got it to work by adding the… May 16, 2026 at 2:20 pm
  • Editorial Team
    Editorial Team added an answer UPDATE 2: Well, you say in a comment that you… May 16, 2026 at 2:20 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to remove the image border in ie, but I get some strange
I've come across some strange behavior trying to get files that start with a
I'm trying to grab out some information from Active Directory using Powershell, but I
Having some strange behavior here. I have some XSLT which generates some html with
I encountered some strange behavior which hints that I do not understand some basic
I'm getting some strange behavior... when I iterate over the dummyText List in the
I am experiencing some strange behavior with OSQL, and would appreciate any help. I
For some strange reason, whenever I have a selector and expect to get multiple
My installation of XCode 3.2 has begun to exhibit some strange behaviour. When I
I was debugging some c++ code (WinCE 6 on ARM platform), and i find

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.