+ 2
Please any one tell me what is vector in c++ ???
I want know the vector meaning and the use of it. And note that I am a beginner.(sorry for any spelling mistakes)
3 Respuestas
+ 6
Vector is a type of container. The SoloLearn course won’t cover this.
It is similar to an array, but you don’t have to worry about a maximum number of elements.
For example:
#include <iostream>
#include <vector>
using namespace std;
int main() {
//this makes a vector of integers named vec. It is currently empty.
vector<int> vec;
//this adds 3 items to it: 3, 8, 479.
vec.push_back(3);
vec.push_back(8);
vec.push_back(479);
//you can access vectors just like arrays.
vec[1] = 56;
cout << vec[0] << endl;
cout << vec[1] << endl;
cout << vec[2] << endl;
}
Outputs:
3
56
479
+ 1
its a dynamic array, it can adjust its size