C++ String Finding a single Character Question

Introduction

Write a program that defines the main string with a value of "Hello C++ World." and checks if a single character 'C' is found in the main string.

You can use the following code structure.

#include <iostream> 

int main() 
{ 
    //your code here
} 


#include <iostream> 
#include <string> 

int main() 
{ 
    std::string s = "Hello C++ World."; 
    char c = 'C'; 
    auto characterfound = s.find(c); 
    if (characterfound != std::string::npos) 
    { 
         std::cout << "Character found at position: " << characterfound <<  
          '\n'; 
    } 
    else 
    { 
        std::cout << "Character was not found." << '\n'; 
    } 
} 



PreviousNext

Related