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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:37:11+00:00 2026-05-22T16:37:11+00:00

I could not figure out what went wrong when I tried to modify vector

  • 0

I could not figure out what went wrong when I tried to modify vector array.
Here is my vector array:

14248 DL AAAAA
14248 DL AAAAA
14248 DL AAAAA
14248 DL AAAAA
14248
14248
14248
14248

What I want to try to do here is, if vector string contains “AAAAA” I will push back as “-” to different vector cRntiModDash. If NOT “AAAAA”, then I push back original string.

So, the cRntiModDash vector should be contained after modified:

-
-
-
-
-
14248
14248
14248
14248
14248

This is what I want, but when I push back to multi-vector all, then something wrong and caused the exit.

std::vector<std::vector<string>*> all;
vector<std::string> cRntiModDash;                   
for (vector < string >::iterator ct(cRnti.begin()); ct != cRnti.end(); ct++)
{ 
    std::string cRntTmp (*ct);
    if (cRntTmp.find("AAAAA") != string::npos)
        cRntiModDash.push_back("-");
    else
        cRntiModDash.push_back(*ct);
    }
}
all.push_back(&cRntiModDash);


for (unsigned int j = 0; j < cRnti.size(); j++)
{
  for (std::vector<std::vector<string>*>::iterator i = all.begin(); i != all.end(); i++)
  {
      if (i != all.begin()) 
      {
         CSVToFile << ",";
         std::cout<< ",";
      }
    std::cout<< (**i)[j];
    CSVToFile <<(**i)[j];
  }
  std::cout<< std::endl;
  CSVToFile << std::endl;
}
CSVToFile.close();

If I don’t modify vector cRnti, then it is OK. I had checked my modified vector did not have any spaces. If someone can recognize my problem, I am really appreciate. I had been tried for while but could not see the problem. Thanks in advance.

  • 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-22T16:37:12+00:00Added an answer on May 22, 2026 at 4:37 pm
    vector<std::string> cRntiModDash;                   
    // ...
    all.push_back(&cRntiModDash);
    

    You store a pointer to the (presumably) local variable cRntiModDash in all. As soon as cRntiModDash goes out of scope, all will contain a pointer to a not longer valid object. That memory location will be reused by other variables and anything might happen when you try to access the vectors in all later on.

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

Sidebar

Related Questions

after reading the Zend documentation and some posts here I could not figure out
I went through all the examples online and could not figure out how to
i just could not figure out how i will put my data on a
I'm trying to play with inter-process communication and since I could not figure out
I am looking at the query syntax . and i could not figure out
it looks very basic thing but i could not figure it out. var email
I'm not seeing the error and was hoping someone could figure it out: public
Probably simple but could not figure out. I am loading an assembly at runtime
I have been trying this for some time but could not figure out yet.
I could not figure out how to pass a variable number of variables 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.