ccplusplus.com
Learn C, C++ Concepts
Sunday, January 8, 2012
stream iterator example c++
/*********************************************************************** * File : stream-iterator.cpp * Author : Saurabh Gupta * Desc : stl stream iterator example c++ * Source : http://ccplusplus/2011/10/standard-template-library.html * Created : PM 06:28 08 January 2012 * Note : the code isn't tested well, please do check that. ************************************************************************/ #include
#include
#include
#include
#include
using namespace std; int main() { vector
coll; /* * read all words from the standard input * - source: all strings until end-of-file (or error) * - destination: coll (inserting) */ copy (istream_iterator
(cin), //start of source istream_iterator
(), //end of source back_inserter(coll)); //destination //sort elements sort (coll.begin(), coll.end()); /* * print all elements without duplicates * - source: coll * - destination: standard output (with newline between elements) */ unique_copy (coll.begin(), coll.end(), //source ostream_iterator
(cout, "\n")); //destination return 0; }
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment