vector<int> a; // empty vector of ints
vector<int> b (5, 10); // five ints with value 10
vector<int> c (b.begin(),b.end()); // iterating through second
vector<int> d (c); // copy of c
#include <iostream>
#include <vector>
#define M 3
#define N 4
int main()
{
// specify default value to fill the vector elements
int default_value = 1;
// first initialize a vector of ints with given default value
std::vector<int> v(N, default_value);
// Use above vector to initialize the two-dimensional vector
std::vector<std::vector<int>> matrix(M, v);
// This vector initializes with the values: 10, 20, and 30
vector<int> vect{ 10, 20, 30 };
return 0;
}
#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;
}
#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;
}
#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;
}