Mega Code Archive

 
Categories / C++ Tutorial / List
 

Make a list of floats from a list of ints

#include <iomanip> #include <iostream> #include <list> #include <vector>  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 int data[] = { 1, 1, 2, 3, 5 };    list<int> original( data,data + sizeof( data ) / sizeof( data[0] ) );    // make a list of floats from a list of ints    list<float> list_float( original.begin(), original.end() );    // show results    print( original);    print( list_float ); }