Initialize a list with values in a vector : list insert « List « C++






Initialize a list with values in a vector

  
#include <algorithm>
#include <iostream>
#include <list>
#include <vector>

using namespace std;

int main( )
{
   short v[] = { 1, 2, 3, 4, 5, 6 };

   vector<short> v1( v,v + sizeof( v ) / sizeof( v[0] ) );

   vector<short> v2( v1 );


   list<short> l( v1.begin(), v1.end() );
   
   if( v1.size() == l.size() && equal( v1.begin(), v1.end(), l.begin() ) )
      cout << "The vector and list are equal" << endl;
   else
      cout << "The vector and list are not equal" << endl;
}
  
    
  








Related examples in the same category

1.Insert elements of array into a list
2.Combine insert and begin to add element to the start of a list
3.Combine insert and end to add elements to the end of a list
4.Fill list with random numbers with generate function
5.Move position pointer and insert again