Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
fill.cpp
Go to the documentation of this file.
1
29#include <algorithm> // for copy(), fill()
30#include <iostream> // for cout
31#include <iterator> // for ostream_iterator
32#include <vector> // for vector
33
34#include <examples.h>
35
36
37int main ()
38{
39 // Typedef for convenience.
40 typedef std::vector<int, std::allocator<int> > Vector;
41
42 const Vector::value_type arr[] = { 1, 2, 3, 4 };
43
44 // Set up two vectors.
45 Vector v1 (arr, arr + sizeof arr / sizeof *arr);
46 Vector v2 (v1.begin (), v1.end ());
47
48 // Set up one empty vector.
49 Vector v3;
50
51 // Fill all of v1 with 9.
52 std::fill (v1.begin (), v1.end (), 9);
53
54 // Fill first 3 of v2 with 7.
55 std::fill_n (v2.begin (), 3, 7);
56
57 // Use insert iterator to fill v3 with 5 11's.
58 std::fill_n (std::back_inserter (v3), 5, 11);
59
60 // Copy all three to cout.
61 std::ostream_iterator<Vector::value_type,
62 char,
63 std::char_traits<char> > out (std::cout, " ");
64
65 std::copy (v1.begin (), v1.end (), out);
66 std::cout << std::endl;
67
68 std::copy (v2.begin (), v2.end (), out);
69 std::cout << std::endl;
70
71 std::copy (v3.begin (), v3.end (), out);
72 std::cout << std::endl;
73
74 // Fill cout with 3 5's.
75 std::fill_n (out, 3, 5);
76 std::cout << std::endl;
77
78 return 0;
79}
#define v2
Definition 17.names.cpp:271
#define v1
Definition 17.names.cpp:245
std::vector< UserClass, std::allocator< UserClass > > Vector
const int out
int main()
Definition fill.cpp:37