fork download
  1. // C++ Program to demonstrate the working of
  2. // begin(), end(), rbegin(), rend()
  3. #include <iostream>
  4. #include <string> // for string class
  5. using namespace std;
  6.  
  7. // Driver Code
  8. int main()
  9. {
  10. // Initializing string`
  11. string str = "geeksforgeeks";
  12.  
  13. // Declaring iterator
  14. std::string::iterator it;
  15.  
  16. // Declaring reverse iterator
  17. std::string::reverse_iterator it1;
  18.  
  19. // Displaying string
  20. cout << "The string using forward iterators is : ";
  21. for (it = str.begin(); it != str.end(); it++)
  22. cout << *it;
  23. cout << endl;
  24.  
  25. // Displaying reverse string
  26. cout << "The reverse string using reverse iterators is "
  27. ": ";
  28. for (it1 = str.rbegin(); it1 != str.rend(); it1++)
  29. cout << *it1;
  30. cout << endl;
  31.  
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0.01s 5392KB
stdin
Standard input is empty
stdout
The string using forward iterators is : geeksforgeeks
The reverse string using reverse iterators is : skeegrofskeeg