A question of vector

S

slchen

Now, I have a question about vector.
I want to create a vector add, it includes two subvector(t1 and t2)
;i,e, add = [t1,t2]
First I declare the two vector t1,t2. Then I initialize the value of
add by t1.
Finally, I assign the t2 to add[1]
==================================
int main()
{
int tt1[] ={1,0,1,1,0};
vector <int> t1(tt1,tt1+6);
int tt2[]={1,1,0,1,1};
vector <int> t2 (tt2,tt2+6);
vector <int> add(2);
vector <int> t1(add);//error in this, initial the t1 into the add,I
// wish the add become [t1,t2]
add[1]= t2;
......
}
===============

How could I fix the code to achieve my goal?
Thanks a lot!

Sen-Lung Chen
 
A

Alan Johnson

Now, I have a question about vector.
I want to create a vector add, it includes two subvector(t1 and t2)
;i,e, add = [t1,t2]
First I declare the two vector t1,t2. Then I initialize the value of
add by t1.
Finally, I assign the t2 to add[1]
==================================
int main()
{
int tt1[] ={1,0,1,1,0};
vector <int> t1(tt1,tt1+6);
int tt2[]={1,1,0,1,1};
vector <int> t2 (tt2,tt2+6);
vector <int> add(2);
vector <int> t1(add);//error in this, initial the t1 into the add,I
// wish the add become [t1,t2]

You've already declared a variable t1. You can't declare a second one.
add[1]= t2;
.....
}
===============

How could I fix the code to achieve my goal?
Thanks a lot!

Sen-Lung Chen

Perhaps what you are trying to do is something like:

vector<int> add ;
add.insert(add.end(), t1.begin(), t1.end()) ;
add.insert(add.end(), t2.begin(), t2.end()) ;

-Alan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top