Mega Code Archive

 
Categories / C++ Tutorial / STL Algorithms Non Modifying Sequence Operations
 

Use istream_iterator and find

#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 after y The first nonwhite-space character following the first 'x' was 'i'.