Print a container (container) element using the copy function
This address: Http://blog.csdn.net/caroline_wendy
C + + is able to replace the for loop with elements from the copy function output container (container) .
Header file:
#include <algorithm>
#include <iterator>
Format:
Std::copy (Cont.begin (), Cont.end (),std::ostream_iterator<type> (Std::cout, ""));
The type is the one that requires the output format, such as the container is Vector<int>, and the type is int.
Code:
/* * main.cpp * * Created on:2014 June 17 * author:spike * * #include <iostream> #include <algorithm> #in Clude <iterator> #include <vector>using namespace Std;int main (void) {std::vector<int> VI = {1, 2, 3, 4, 5};std::copy (Vi.begin (), Vi.end (), std::ostream_iterator<int> (Std::cout, "")); std::cout << Std::endl; return 0;}
Output:
C + +-print container (container) elements using the copy function