C++ Char Start with [P] and Convert

closed account (ypk91hU5)
C++ Version 11
How to start basic code for below code?

The program should be in the loop.
If the first character is the letter lowercase g then....
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>     // std::cout
#include <sstream>      // std::istringstream
#include <string>       // std::string
#include <algorithm>    // std::transform, std::reverse

void myConvert(const std::string& str){
    std::istringstream iss(str);
    std::string s;
    while(iss>>s){
        if(s[0]=='P')
            std::transform(s.begin(), s.end(), s.begin(), ::tolower);
        else if(s[0]=='g')
            std::reverse(s.begin(), s.end());
        else
            s = "Not exist";
        std::cout<<s<<std::endl;
    }
}

int main () {

  std::string str1 = "People like to see me!";
  std::string str2 = "good is nothing";
  
  myConvert(str1);
  myConvert(str2);

  return 0;
}
Last edited on
Topic archived. No new replies allowed.