vector::operator= | public member function |
vector<T,Allocator>& operator= (const vector<T,Allocator>& x); |
Copy vector content
Assigns a copy of vector x as the new content for the vector object.
The elements contained in the vector object before the call are dropped, and replaced by copies of those in vector x, if any.
After a call to this member function, both the vector object and vector x will have the same size and compare equal to each other.
Parameters
- x
- A vector object containing elements of the same type.
Return value
*thisExample
// vector assignment #include <iostream> #include <vector> using namespace std; int main () { vector<int> first (3,0); vector<int> second (5,0); second=first; first=vector<int>(); cout << "Size of first: " << int (first.size()) << endl; cout << "Size of second: " << int (second.size()) << endl; return 0; } |
Size of first: 0 |
Complexity
Linear on sizes (destruction, copy construction).See also
vector::assign | Assign vector content (public member function) |