Search
 
SCRIPT & CODE EXAMPLE
 

CPP

C++ Vector Initialization method 01

#include <iostream>
#include <vector>
using namespace std;

int main() {
    
    // initializer list
  vector<int> vect = {1, 2, 3, 4, 5};
  
  cout << "vector = ";

  // ranged loop
  for (const int& i : vect) {
    cout << i << "  ";
  }
  
  return 0;
}
Comment

C++ Vector Initialization method 02

#include <iostream>
#include <vector>
using namespace std;

int main() {
    
  // uniform initialization
  vector<int> vect{1, 2, 3, 4, 5};
  
  cout << "vector = ";

  // ranged loop
  for (const int& i : vect) {
    cout << i << "  ";
  }
  
  return 0;
}
Comment

C++ Vector Initialization method 03

#include <iostream>
#include <vector>
using namespace std;

int main() {
    
 // method 3
  vector<int> vect(5, 10);
  
  cout << "vector = ";

  // ranged loop
  for (const int& i : vect) {
    cout << i << "  ";
  }
  
  return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: cplusplus 
Cpp :: compile c++ program 
Cpp :: Problems in your to-do list codechef solution in c++ 
Cpp :: for in c++ example 
Cpp :: changing key bindings in visual code not working 
Cpp :: c++ operators 
Cpp :: thread group c++ 
Cpp :: // A C++ program to show that we can use reference to 
Cpp :: run c++ files on chrome book 
Cpp :: convert c++ code to exe 
Cpp :: qt/c++ exception handler 
Cpp :: how can I convert each and every element of string push into set in c++? 
Cpp :: how to make a goto area in c++ 
Cpp :: c++ how to print out 
Cpp :: inversed priority queue 
Cpp :: template in cpp 
Cpp :: online c++ compiler 
Cpp :: c++ multi-dimensional arrays 
Cpp :: constants in cpp 
Cpp :: vector to char array c++ 
Cpp :: c++ return statement 
Cpp :: c++ delete int 
C :: auto click connect colab 
C :: terminal count files in directory 
C :: c get file size 
C :: how to print helloq world in c 
C :: font awsome circle info icon 
C :: two bytes to int c 
C :: how to print a file c 
C :: find length of int number in c 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =