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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:38:30+00:00 2026-06-15T07:38:30+00:00

The goal of my test program is to erase a cell in a simple

  • 0

The goal of my test program is to erase a cell in a simple vector of strings like below.
The program fail (segmentation fault).

static void display(std::vector<std::string> const &vec)
{
    std::vector<std::string>::const_iterator It = vec.begin();
    for (; It != vec.end(); ++It)
        std::cout << *It << " ";
    std::cout << std::endl;
}


int         main(void)
{
    std::vector<std::string> vec;
    size_t  index = 0;

    vec.push_back("Toto");
    vec.push_back("Titi");
    vec.push_back("Tata");
    vec.push_back("Tutu");

    display(vec);

    std::vector<std::string>::iterator It = vec.begin();

    for (size_t idx = 0; It != vec.end(); ++It, idx++)
        if (!(*It).compare("Tutu"))
            index = idx;

    vec.erase(std::remove(vec.begin(), vec.end(), index), vec.end()); //Segmentation fault

    display(vec);

    getchar();
    return (0);
}

Does anyone can help me? Thanks in advance for your help.

  • 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-15T07:38:32+00:00Added an answer on June 15, 2026 at 7:38 am
    vec.erase(std::remove(vec.begin(), vec.end(), index), vec.end());
    

    You need to pass the actual element (in this case of type std::string) to your erase function.

    So instead of index, it should be somestring

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

Sidebar

Related Questions

My goal is to make a simple TCP proxy application for my test lab.
I just wrote this test code in my CustomUIPanel class: public static void main(String[]
So we're almost at our goal to test-drive our spring web-mvc application. We're using
If your goal is to test if a string exists in a MySQL column
For example, my goal is to test the code given here: PHP script that
Goal I am building an Eclipse plugin targeting the 3.7 environment and would like
GOAL : To customize the background view of cell. Here is what I am
This question might be a little specific but the test program im writing uses
The goal is to create a program which will effectively let the user create
I'm trying to translate my java program into Haskell. My goal is to split

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.