Storing Specific Values in an Existing Container : vector definition « Vector « C++






Storing Specific Values in an Existing Container

  
#include <string>
#include <vector>

#include <iostream>

using namespace std;

template <class T>
void print(T& c){
   for( typename T::iterator i = c.begin(); i != c.end(); i++ ){
      std::cout << *i << endl;
   }
}

int main( )
{
   const char* s[] = { "A", "B", "C", "D", "Don't know" };

   vector<string> answers( s, s+ sizeof( s ) / sizeof( s[0] ) );
   print( answers ); 

   const char* s1[] = { "A", "C", "B","D", "V", "O" };
   answers.assign( s1, s1 + sizeof( s1 ) / sizeof( s1[0] ) );
   print( answers );
}
  
    
  








Related examples in the same category

1.vector declaration
2.vector's copy constructor