By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,911 Members | 1,171 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,911 IT Pros & Developers. It's quick & easy.

A question of vector

P: n/a
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

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
sl****@larc.ee.nthu.edu.tw wrote:
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
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.