Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ vector size

#include <vector>

int main() {
  std::vector<int> myVector = { 666, 1337, 420 };
  
  size_t size = myVector.size(); // 3
  
  myVector.push_back(399); // Add 399 to the end of the vector
  
  size = myVector.size(); // 4
}
Comment

vector size

#include<iostream>
#include<vector>
using namespace std;
int main(){
  //Creation of integer vector
  vector<int> vectorArray {1,2,3,4,5,6,7,8,9};
  //Created vector has 9 elements on it 
  int sizeOf_vectorArray= vectorArray.size();
  
  cout<<sizeOf_vectorArray; // Output will be 9
  
  vectorArray.push_back(10); // 10 will be added in the end of the vector
  
  sizeOf_vectorArray=vectorArray.size();
  
  cout<<sizeOf_vectorArray; // Output will be 10
  
  vectorArray.push_front(0); //0 will be added in the begining of the vector
  
  sizeOf_vectorArray=vectorArray.size();
  
  cout<<sizeOf_vectorArray; // Output will be 11
  
  return 0;
} 
Comment

vector size c++

size() function is used to return the size of the vector container or the number of elements in the vector container.
using namespace std;
int main(){
    vector<int> myvector{ 1, 2, 3, 4, 5 };
    cout << myvector.size();
    return 0;
}
//Output = 5
Comment

PREVIOUS NEXT
Code Example
Cpp :: calculator in cpp 
Cpp :: iostream c++ 
Cpp :: c++ for each loop 
Cpp :: abstraction in cpp 
Cpp :: C++ sum a vector of digits 
Cpp :: take a function as an argument in c++ 
Cpp :: add matic mainnet to metamask mobile 
Cpp :: int max in c++ 
Cpp :: initialise 2d vector in c++ 
Cpp :: fill two dimensional array c++ 
Cpp :: fstream read write mode 
Cpp :: loop execution descending order in c++ 
Cpp :: for statement c++ 
Cpp :: c++ recorrer string 
Cpp :: glfw error: the glfw library is not initialized 
Cpp :: potato 
Cpp :: recursive factorial of a number 
Cpp :: modular exponentiation algorithm c++ 
Cpp :: namespace file linking c++ 
Cpp :: unordered_map c++ 
Cpp :: time complexity 
Cpp :: new in c++ 
Cpp :: C++ Vector Operation Delete Elements 
Cpp :: know what the input data is whether integer or not 
Cpp :: binary tree 
Cpp :: remove duplicates from sorted list solution in c++ 
Cpp :: lcm in c++ 
Cpp :: vector insert to end 
Cpp :: top array data structure questions in inteviews 
Cpp :: sort array in descending order c++ 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =