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

  • Home
  • SEARCH
  • 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 115047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:57:26+00:00 2026-05-11T02:57:26+00:00

I want to insert a pair< string, vector<float> > into a map, first it

  • 0

I want to insert a pair< string, vector<float> > into a map, first it works, but after several loops, it cannot insert any more and throw me a segmentation fault. Can anybody give a possible reason?

Btw: I first read a file and generate the map (about 200,000 elements) and I read another file and update the old map. the error occurs while the updating step.

Can anybody help me with the info I gave above? Thanks a lot

The code is pretty long…..I just erase the previous key and then insert a new one, it seems not complicated…..but drives me crazy….could you guess what happened here?

Thanks A lot for all your answers! And I found it is really a good place for solving problems. Thanks again, I’ll try to simplify my codes and add it here today or tomorrow.

Update: I used the code from MSN and it works, thanks a lot that you solved my problem without seeing my code……also many thanks to other kind-hearted people here! However, i can only choose one as the answer.

  • 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. 2026-05-11T02:57:27+00:00Added an answer on May 11, 2026 at 2:57 am

    The type in question is pair<string, vector<float> >. You will be copying that pair on every insert. If either the string or the vector are big then you could be running out of memory.

    Edit: to fix running out of memory, you can change how you insert key-value pairs to:

    pair<map::iterator, bool> insert_result= map.insert(make_pair(name, vector<float>()); if (insert.second) { insert_result.first->second.swap(vector_read_in); } 

    That will ensure that you do not copy memory, only move it.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to use the command line tool TF.EXE (use… May 11, 2026 at 4:12 pm
  • Editorial Team
    Editorial Team added an answer Not needed, although you may want to consider always building… May 11, 2026 at 4:12 pm
  • Editorial Team
    Editorial Team added an answer You can either use libparted from GNU parted (http://www.gnu.org/software/parted/index.shtml) or… May 11, 2026 at 4:12 pm

Related Questions

I have a problem with a string in C++ which has several words in
I want to fill a map with class name and method, a unique identifier
I'm looking for a C++ container class, that's a lot like a multimap, but
I have a template class where I want to use objects of that class

Trending Tags

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

Top Members

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.