“taille vectorielle” Réponses codées

C.

#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
}
Bright Badger

taille vectorielle

#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;
} 
Manaj Bera

Taille vectorielle 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
Sleepy Head

Réponses similaires à “taille vectorielle”

Questions similaires à “taille vectorielle”

Plus de réponses similaires à “taille vectorielle” dans C++

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code