Mega Code Archive

 
Categories / C++ Tutorial / String
 

Using find with reverse iteration

#include <iostream> #include <vector> #include <algorithm> // for find #include <iterator> using namespace std; int main() {   string s("It is him.");   vector<char> vector1(s.begin(), s.end());   ostream_iterator<char> out(cout, " ");   cout << "chars from the last t to the beginning: ";   vector<char>::reverse_iterator r = find(vector1.rbegin(), vector1.rend(), 't' );   copy(r, vector1.rend(), out); cout << endl;   cout << "chars from the last t to the end: ";   copy(r.base() - 1, vector1.end(), out); cout << endl;   return 0; } chars from the last t to the beginning: t I chars from the last t to the end: t i s h i m .