// vector_ctor.cpp // compile with: /EHsc #include #include int main( ) { using namespace std; vector ::iterator v1_Iter, v2_Iter, v3_Iter, v4_Iter, v5_Iter; // Create an empty vector v0 vector v0; // Create a vector v1 with 3 elements of default value 0 vector v1( 3 ); v1.push_back(123); cout << "v1[0] = " << v1[0] << " v1[3] = " << v1[3] << endl; // Create a vector v2 with 5 elements of value 2 vector v2( 5, 2); v2.push_back(123); cout << "v2[0] = " << v2[0] << " v2[5] = " << v2[5] << endl; // Create a vector v3 with 3 elements of value 1 and with the allocator // of vector v2 vector v3( 3, 1, v2.get_allocator( ) ); // Create a copy, vector v4, of vector v2 vector v4( v2 ); // Create a vector v5 by copying the range v4[_First, _Last) vector v5( v4.begin( ) + 1, v4.begin( ) + 3 ); cout << "v1 =" ; for ( v1_Iter = v1.begin( ) ; v1_Iter != v1.end( ) ; v1_Iter++ ) cout << " " << *v1_Iter; cout << endl; cout << "v2 =" ; for ( v2_Iter = v2.begin( ) ; v2_Iter != v2.end( ) ; v2_Iter++ ) cout << " " << *v2_Iter; cout << endl; cout << "v3 =" ; for ( v3_Iter = v3.begin( ) ; v3_Iter != v3.end( ) ; v3_Iter++ ) cout << " " << *v3_Iter; cout << endl; cout << "v4 =" ; for ( v4_Iter = v4.begin( ) ; v4_Iter != v4.end( ) ; v4_Iter++ ) cout << " " << *v4_Iter; cout << endl; cout << "v5 ="; for ( v5_Iter = v5.begin( ) ; v5_Iter != v5.end( ) ; v5_Iter++ ) cout << " " << *v5_Iter; cout << endl; }