string reverse iterator c 2b 2b

Solutions on MaxInterview for string reverse iterator c 2b 2b by the best coders in the world

showing results for - "string reverse iterator c 2b 2b"
Mariana
06 Aug 2019
1// string::rbegin/rend
2#include <iostream>
3#include <string>
4
5int main ()
6{
7  std::string str ("now step live...");
8  for (std::string::reverse_iterator rit=str.rbegin(); rit!=str.rend(); ++rit)
9    std::cout << *rit;
10  return 0;
11}
Marie
21 Jul 2018
1...evil pets won
2
Ezio
08 Mar 2017
1#include <iostream>
2using namespace std;
3
4int main() {
5 
6  string greeting = "Hello";
7  int len = greeting.length();
8  int n=len-1;
9  for(int i=0;i<(len/2);i++){
10    //Using the swap method to switch values at each index
11    swap(greeting[i],greeting[n]);
12    n = n-1;
13
14  }
15  cout<<greeting<<endl;
16}