+ 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)

21st Jan 2018, 12:58 AM
Subrahmanya Mayya
Subrahmanya Mayya - avatar
3 Answers
21st Jan 2018, 6:33 AM
Hatsy Rei
Hatsy Rei - avatar
+ 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
21st Jan 2018, 1:51 AM
Jacob Pembleton
Jacob Pembleton - avatar
+ 1
its a dynamic array, it can adjust its size
21st Jan 2018, 3:09 AM
shobhit
shobhit - avatar