Beginning and Ending Iterators of C-Style Arrays : copy « STL Algorithms Modifying sequence operations « C++






Beginning and Ending Iterators of C-Style Arrays

  
#include <algorithm>
#include <iostream>
#include <iterator>

using namespace std;

int main( )
{
   const int num_costs = 4;
   const float cost[num_costs] = { 11.11, 22.22, 33.33, 44.44 };
   copy( cost, cost + num_costs,ostream_iterator<float>( cout, "     " ) );


   const char* fruit[] = { "A", "B", "C" };
   copy( fruit, fruit + sizeof( fruit ) / sizeof( fruit[0] ),
      ostream_iterator<const char*>( cout, "    " ) );

   int year[] = { 2001, 2002, 2003, 2004, 2005 };
   const int num_years = sizeof( year ) / sizeof( year[0] );
   copy( year, year + num_years,ostream_iterator<int>( cout, "    " ) );

   sort( year, year + num_years );
   copy( year, year + num_years,ostream_iterator<int>( cout, "    " ) );

   reverse( year, year + num_years );
   copy( year, year + num_years,ostream_iterator<int>( cout, "    " ) );
}
  
    
  








Related examples in the same category

1.Copy vector and list
2.Use copy to copy elements in one container to another container
3.Copy and insert list
4.Use copy function to print all elements in a deque
5.Print all elements in a list with copy function
6.Use std::copy to print all elements in a set
7.Display all elements in a vector
8.Use copy to output all elements in a container
9.Use copy to copy elements of one container into another container in reverse order
10.Copy all letters three elements behind the 'f'
11.Copy istream_iterator to ostream_iterator
12.Use the copy algorithms: Shift the contents of vector1 left by 4 positions
13.Use the generic copy to duplicate vectors
14.Use copy to fill values to an array
15.Displaying a Container's Elements on the Standard Output with copy function