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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:07:01+00:00 2026-05-20T14:07:01+00:00

Dear All, I used a vector of vector, say vector<vector<int> > no_1_2 to store

  • 0

Dear All,
I used a vector of vector, say vector<vector<int> > no_1_2 to store elements of two vector<int> containers, say no1 & no2. so for e.g. i would say, no1={2,5,7,10,3} and no2={21,34,15}.

I wanted to store these 2 vectors in one container called no_1_2 and I used no_1_2[0].push_back(no1.at(i)) and no_1_2[1].push_back(no2.at(j)) within two ‘for’ loops. But, i got error. is there anyway to solve this?

Can’t i push_back vector of vector? any help please..
thanks

sorry here is part of my code,
//some classes and some codes are here

vector< vector<int> > final_list(int code1,int code2){
   vector<vector<int> > no_1_2;
   vector<int> in;
   vector<int> out;
   for (int foo=0;foo<size();foo++){
       int a_point=foo;
       if (at(a_point).Code()==code1){
           vector<int> closer_points;
           closer_points=at(foo).Closers();
           for (int fee=0;fee<closer_points.size();fee++){
               int a_neb_point=closer_points.at(fee);
               if (at(a_neb_point).Code()==code2){
                    in.push_back(a_point);  
                    out.push_back(a_neb_point);  
                    }
               }
           }
       }
   /remove duplicates // above in and out vectors containing some values repeatedly, so, i remove the duplicates here
   for(vector<int>::iterator i=in.begin();i!=in.end();i++){
     sort(in.begin(),in.end());
     in.erase(unique(in.begin(),in.end()),in.end()); 
     no_1_2[0].push_back(*i);
     }
   for(vector<int>::iterator o=out.begin();o!=out.end();o++){
     sort(out.begin(),out.end());
     out.erase(unique(out.begin(),out.end()),out.end());
     no_1_2[1].push_back(*o);
     }
   return no_1_2;
   }

int main (){
// some code

vector< vector <int> > in_out=mylist.final_list(34,1); //here i just tried for code    values for (34, 1), like that i have many sets
}
  • 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-20T14:07:01+00:00Added an answer on May 20, 2026 at 2:07 pm

    Without seeing your actual code and errors, let me guess:

    You didn’t call no_1_2.resize(2) before you accessed no_1_2[0] or no_1_2[1]

    EDIT: After seeing code, the above’s no longer guesswork:

    You cannot do no_1_2[0].push_back(*i); – no_1_2 is empty and you’re trying to access no_1_2[0]. You will need to resize it before the loop.

    EDIT2:

    Move your sort/unique/erase outside the loops, and use assign or operator=:

    sort(in.begin(),in.end());
    in.erase(unique(in.begin(),in.end()),in.end()); 
    no_1_2[0].assign(in.begin(), in.end());
    // OR: no_1_2[0] = in;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Dear All, I have 2 input string 1)stack,over,flow 2)stack/over,flow,com I would like to print
dear all, i'll take some data from the database. and join two tables.the code
dear all, i need to combine two different result in one script. The problem
dear all, i have two buttons inside my page. i want for the 1st
Dear all, Given a variable that takes on, say, three values, I'm trying to
Dear all, I am writing a python program that is retrieving edifact log messages
Dear all: In advance, thank you for your time. Lately, I have decided to
dear all.i newbie at web programming and until now i still have learn about
dear all,this is my code at xampp: $sql = INSERT INTO oqc_defect ; $sql.=
dear all.can you tell me how to collecting this data in mysql: item colour

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.