Q:

Write a C++ program to check if a given string starts with 'C#' or not

0

Write a C++ program to check if a given string starts with 'C#' or not

Sample Output:

1
1
0

All Answers

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

#include <iostream>

using namespace std;

 bool test(string str)
        {
            return (str.length() < 3 && str=="C#") || (str.substr(0,2)=="C#" && str[2] == ' ');
        }
        
int main() 
 {
  cout << test("C# Sharp") << endl;  
  cout << test("C#") << endl;  
  cout << test("C++") << 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