GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Saturday, December 18, 2010

C++ STL - Using Vector

Vector is a dinamic array. For using vector as your data structure in C++, you need to declare it plus include <vector> header file:

>> vector data;                // use generic type

Then to insert a data to it, you use:
>> data.push_back("steve jobs");
>> data.push_back("larry page");

To access an element of this data, you use [] operator:
>> cout << data[0];
>> cout << data[0];

You can just delete the last entry data:
>> data.pop_back();

To get the size of the data, use:
>> cout << "Size: " << data.size();

    
Share/Bookmark

No comments:

Post a Comment