for (i = 0; i < src.size(); i++) dst.push_back(src[i])
for (i = 0; i < ivec.size(); i++)
if even(ivec[i])
evens.push_back(ivec[i])
outi copy(outi d, ini b, ini e)
while b != e
*d++ = *b++
return d
std::vector v1(10);
std::list l2;
copy(l2.begin(), v1.begin(), v1.end())
std::vectorv1(10); std::list l2(v1.begin(), v1.end());
<iterator>.
*, pre and post ++, and assignment.
template < class ContainerT >
class back_insert_iterator { ... };
vector<int> ivec; back_insert_iterator<vector<int> > bi(ivec);
std::back_inserter(c, pos).
copy( l1.begin(), l1.end(), back_insert_iterator<vector<int> >(v1)) copy( l1.begin(), l1.end(), back_inserter(v1))
*bi++ = v pushes v onto the end of c.
template < class ContainerT >
back_insert_iterator {
ContainerT cont
back_insert_iterator(ContainerT c)
: cont(c) { }
operator = (ContainerT::value_type v)
cont.push_back(v);
operator * (void)
return * this;
// similarly for pre and post ++
}
vector<int> ivec; back_insert_iterator<vector<int> > bi(ivec);bi[1] = 3
push_back().
*bi++ = 3 // ok but redundant.bi = 4// ok but confusing.
template < class ContainerT >
class front_insert_iterator { ... };
vector<int> ivec; front_insert_iterator<vector<int> > fi(ivec);
std::front_inserter(c).
std::copy( l1.begin(), l1.end(), std::front_inserter(v1))
template < class ContainerT >
class insert_iterator { ... };
vector<int> ivec(10); insert_iterator<vector<int> > bi(ivec, ivec.begin() + 1);
std::inserter(c, i).
*bi++ = v inserts v at the initial iterator.
for (i = 0; i < src.size(); i++)dst.push_back(src[i])std::copy( src.begin(), src.end(), std::back_inserter(dst))
for (i = 0; i < ivec.size(); i++)if even(ivec[i])evens.push_back(ivec[i])std::remove_copy_if( ivec.begin(), ivec.end(), std::back_inserter(evens), even)
std::ostream &
operator << (std::ostream & os, ivec ints)
ivec_iter i;
for (i = ints.begin(); i != ints.end(); i++)
os << *i
return os
while iss >> i ints.push_back(i)
<iterator>.
template < class ElementT >
class ostream_iterator { ... };
ostream_iterator<int> osi(cout)
const char *.
ostream_iterator<int> osi(cout, ", ")
operator << (ElementT) must be defined.
* and ++ are no-ops; = does the write.
ostream_iterator<int> osi(cout, " "); *osi++ = 1; // write 1 to std-outosi = 2;// write 2 to std-out
template < class ElementT >
class istream_iterator { ... };
std::istream_iterator<int> isi(cin)
operator >> (ElementT) must be defined.
== against the EOS iterator, not .eof().
* returns the most recently read value.
-> returns a field in the most recently read value.
++ reads a new value and returns an istream iterator to it.
++ reads a new value and returns an istream iterator to
the previously read value.
i == j does not imply
*i == *j.
i == j does not imply ++i == ++j. (why?)
std::ostream & operator << (std::ostream & os, pile p)ivec_iter i;for (i = ints.begin(); i != ints.end(); i++)os << *istd::copy(ints.begin(), ints.end(), std::ostream_iterator(os)); return os
while iss >> iints.push_back(i)std::copy( std::istring_stream<int>(iss), std::istring_stream<int>(), std::back_inserter(ints));
This page last modified on 2 March 2004.