Mega Code Archive

 
Categories / C++ / Algorithm
 

Generic find algorithm with input iterators associated with io streams

#include <iostream> #include <cassert> #include <algorithm> #include <list> #include <iterator> using namespace std;  int main()  {   cout << "Type some characters, including an 'x' followed\n"     << "by at least one nonwhite-space character: " << flush;   istream_iterator<char> in(cin);   istream_iterator<char> eos;   find(in, eos, 'x');   cout << "The first nonwhite-space character following\n"        << "the first 'x' was '" << *(++in) << "'." << endl;      return 0; }  /*  Type some characters, including an 'x' followed by at least one nonwhite-space character: x is before y The first nonwhite-space character following the first 'x' was 'i'.  */