Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to append one vector to another c++

vector<int> a;
vector<int> b;
// Appending the integers of b to the end of a 
a.insert(a.end(), b.begin(), b.end());
Comment

assign one vector to another c++

// C++ code to demonstrate copy of vector 
// by iterative method. 
#include<iostream> 
#include<vector> 
using namespace std; 
  
int main() 
{ 
    // Initializing vector with values 
    vector<int> vect1{1, 2, 3, 4}; 
  
    // Declaring new vector 
    vector<int> vect2; 
  
    // Using assignment operator to copy one 
    // vector to other 
    vect2 = vect1; 
  
    cout << "Old vector elements are : "; 
    for (int i=0; i<vect1.size(); i++) 
        cout << vect1[i] << " "; 
    cout << endl; 
  
    cout << "New vector elements are : "; 
    for (int i=0; i<vect2.size(); i++) 
        cout << vect2[i] << " "; 
    cout<< endl; 
  
    // Changing value of vector to show that a new 
    // copy is created. 
    vect1[0] = 2; 
  
    cout << "The first element of old vector is :"; 
    cout << vect1[0] << endl; 
    cout << "The first element of new vector is :"; 
    cout << vect2[0] <<endl; 
  
    return 0; 
}
Comment

assign one vector to another c++


   // Initializing vector with values 
    vector<int> vect1{1, 2, 3, 4}; 
  
    // Declaring new vector 
    vector<int> vect2; 
  
    // Using assignment operator to copy one 
    // vector to other 
    vect2 = vect1; 
Comment

PREVIOUS NEXT
Code Example
Cpp :: statements 
Cpp :: initialize a vector with same values 
Cpp :: how to print an array in cpp in single line 
Cpp :: Arduino Real TIme Clock 
Cpp :: c++ print array of arrays with pointer 
Cpp :: how can I delete a substring from a string in c++? 
Cpp :: c++ map 
Cpp :: cpp undefined reference to function 
Cpp :: oop in c++ have 5 
Cpp :: c++ pointers and arrays 
Cpp :: for_each c++ 
Cpp :: cpp custom exception 
Cpp :: 1. Two Sum 
Cpp :: enum in c++ 
Cpp :: long long vs long long int 
Cpp :: C++ insert character 
Cpp :: c++ virtual function 
Cpp :: print all number between a and b in c++ 
Cpp :: InstallUtil.exe ConsoleApp 
Cpp :: how to bath without water 
Cpp :: OpenCV" is considered to be NOT FOUND 
Cpp :: c++ exeption handling 
Cpp :: error c4001 site:docs.microsoft.com 
Cpp :: setFontSize QT 
Cpp :: c to assembly mips converter 
Cpp :: Shuffle String leetcode solution in cpp 
Cpp :: c++ require keyword 
Cpp :: Print value of data in c++ 
Cpp :: omp multiple reductions 
Cpp :: c++ multiple if conditions 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =