Using find with reverse iteration : string find « String « C++






Using find with reverse iteration

  
 
#include <iostream>
#include <vector>
#include <algorithm> 
#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 .

 */        
    
  








Related examples in the same category

1.search a sub string
2.string.find(substring)
3.string.rfind(substring)
4.string.find_first_of( substring )
5.string.find_last_of(substring)
6.string.find_first_not_of( substring )
7.Find the first that's not in this set, starting from the end
8.Find the first of any of these chars starting from the end
9.Search from the beginning
10.Search from the end
11.Find the first of any of these chars
12.Find the first that's not in this set
13.equivalent of strcspn() and strpbrk()
14.equivalent of strspn()
15.Use the STL find() algorithm to obtain an iterator to the start of the first 'a'