Mega Code Archive

 
Categories / C++ Tutorial / Vector
 

Instantiate a vector to 5 elements taken from another

#include <vector> int main () {    std::vector <int> v;    // Instantiate a vector with 10 elements (it can grow larger)    std::vector <int> v1 (10);    // Instantiate a vector with 10 elements, each initialized to 90    std::vector <int> vecArrayWithTenInitializedElements (10, 90);    // Instantiate one vector and initialize it to the contents of another    std::vector <int> vecArrayCopy (vecArrayWithTenInitializedElements);    // Instantiate a vector to 5 elements taken from another    std::vector<int> vecSomeElementsCopied(v.begin(), v.begin () + 5);    return 0; }