Vector Init Array : vector « vector « C++ Tutorial






#include <iostream>
#include <vector>
using namespace std;

void print( vector<int> );

int main()
{
    int data[] = {11, 12, 23, 34};
    int size = sizeof( data ) / sizeof( data[0] );
    vector<int> vec( data, &data[ size ] );
    print( vec );           // 11 12 23 34
    return 0;
}

void print( vector<int> vec ) {
    vector<int>::iterator p = vec.begin();
    while ( p < vec.end() )
      cout << *p++ << " ";
    cout << endl;
}








16.1.vector
16.1.1.Demonstrating the simplest STL vector constructors: duplicate chars
16.1.2.Demonstrating the simplest STL vector constructors: empty vector
16.1.3.Use generic vector to create vector of chars
16.1.4.Use generic vector to create vector of integers
16.1.5.creates a vector of ints with zero elements
16.1.6.creates a vector of 10 ints with value 100
16.1.7.Use generic vector to create vector of strings
16.1.8.The Instantiation of vector
16.1.9.Using the vector
16.1.10.get an iterator that points to the maximum with max_element
16.1.11.Assign elements in int array to vector
16.1.12.Store a class object in a vector
16.1.13.Read keyboard input to a vector
16.1.14.Add class to a vector and then delete them one by one
16.1.15.Pass vector to a function
16.1.16.Computing an inner product of tuples represented as vectors
16.1.17.Assign value to the last element
16.1.18.Demonstrating STL vector copying constructors
16.1.19.Instantiate one vector and initialize it to the contents of another
16.1.20.Demonstrating STL vector constructors with a user-defined type and showing copying explicitly
16.1.21.Vector Init Array
16.1.22.Demonstrating STL vector constructors with a user-defined type