예제 #1
0
int main()
{
    istream_iterator<int> cin_it(cin);   // reads ints from cin
    istream_iterator<int> end_of_stream; // end iterator value

    // initialize vec from the standard input:
    vector<int> vec(cin_it, end_of_stream);

    sort(vec.begin(), vec.end());

    // writes ints to cout using " " as the delimiter
    ostream_iterator<int> output(cout, " ");  

    // write only the unique elements in vec to the standard output
    unique_copy(vec.begin(), vec.end(), output);
    cout << endl;  // write a newline after the output
    return 0;
}
예제 #2
0
int main ()
{
    // Attaches an istream_iterator to cin.
    std::istream_iterator<int> cin_it(std::cin);
    std::istream_iterator<int> eos;

    // Copy inputs into vector until the end of file.
    std::vector<int> vec(cin_it, eos);
    std::reverse(vec.begin(), vec.end());

    // Attaches an ostream_iterator to cout.
    // The second parameter " " is a nice separator to separate output.
    std::ostream_iterator<int> cout_it(std::cout, " ");

    // Copy all content from vector into cout.
    std::copy(vec.begin(), vec.end(), cout_it);

    return 0;
}