Q:

Write a C++ program to check if a string 'yt' appears at index 1 in a given string. If it appears return a string without 'yt' otherwise return the original string

0

Write a C++ program to check if a string 'yt' appears at index 1 in a given string. If it appears return a string without 'yt' otherwise return the original string

Sample Output:

Phon
ytade
jsues

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
using namespace std;

string test(string str)
        {
            return str.substr(1, 2)=="yt" ? str.erase(1, 2) : str;
        }
        
int main() 
 {
  cout << test("Python") << endl;  
  cout << test("ytade") << endl;  
  cout << test("jsues") << endl;  
  return 0;    
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now