What is vector data-type in C++ ?
-A vector is a sequence container class that implements dynamic array, means size automatically changes when appending elements.
-A vector stores the elements in contiguous memory locations and allocates the memory as needed at run time.
Difference between Vector and array:
-Array is static approach while vector is dynamic approach.
-Array size cannot be changed during run time while vector memory depends on numbers of elements.
program:
#include< iostream>
#include< vector>
using namespace std;
int main()
{
vector< string> v1;
v1.push_back("Data1");
v1.push_back("Data2");
for(vector< string>::iterator itr=v1.begin();itr!=v1.end();++itr)
cout<<*itr<< endl;
return 0;
}
Data1
Data2