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 1 1630 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: {AGUT2}=IWIK= |
last post by:
Hello all,
It's my fisrt post here and I am feeling a little stupid here, so go easy..
:) (Oh, and I've spent _hours_ searching...)
I am desperately trying to read in an ASCII...
|
by: luigi |
last post by:
Hi,
I am trying to speed up the perfomance of stl vector by
allocating/deallocating blocks of memory manually. one version of the
code crashes when I try to free the memory. The other version...
|
by: Forecast |
last post by:
I run the following code in UNIX compiled by g++ 3.3.2 successfully.
: // proj2.cc: returns a dynamic vector and prints out at main~~
: //
: #include <iostream>
: #include <vector>
:
: using...
|
by: Adam Hartshorne |
last post by:
Hi All,
I have the following problem, and I would be extremely grateful if
somebody would be kind enough to suggest an efficient solution to it.
I create an instance of a Class A, and...
|
by: Bob |
last post by:
Here's what I have:
void miniVector<T>::insertOrder(miniVector<T>& v,const T& item)
{
int i, j;
T target;
vSize += 1;
T newVector;
newVector=new T;
|
by: Ross A. Finlayson |
last post by:
I'm trying to write some C code, but I want to use C++'s std::vector.
Indeed, if the code is compiled as C++, I want the container to
actually be std::vector, in this case of a collection of value...
|
by: Martin Jørgensen |
last post by:
Hi,
I get this using g++:
main.cpp:9: error: new types may not be defined in a return type
main.cpp:9: note: (perhaps a semicolon is missing after the definition
of 'vector')
main.cpp:9:...
|
by: Sanjay Kumar |
last post by:
Folks,
I am getting back into C++ after a long time and I have
this simple question: How do pyou ass a STL container
like say a vector or a map (to and from a function) ?
function:
...
|
by: zl2k |
last post by:
hi, there
I am using a big, sparse binary array (size of 256^3). The size may be
changed in run time. I first thought about using the bitset but found
its size is unchangeable. If I use the...
|
by: toton |
last post by:
Hi,
I want to have a vector like class with some additional functionality
(cosmetic one). So can I inherit a vector class to add the addition
function like,
CorresVector : public...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |