C++ Code. Example: x: "This is #my first program"; y: "#my";
bool function(string x, string y)
{
//Return true if y is contained in x
return ???;
}
C++ Code. Example: x: "This is #my first program"; y: "#my";
bool function(string x, string y)
{
//Return true if y is contained in x
return ???;
}
You can use std::string::find()
bool function(string x, string y)
{
return (x.find(y) != std::string::npos);
}
How the function can be written depends on whether the search for an empty string will be considered as successful or not. If to consider that an empty string is present in any string then the function will look as
bool function( const std::string &x, const std::string string &y )
{
return ( x.find( y ) != std::string::npos );
}
If to consider that the search of an empty string shall return false then the function will look as
bool function( const std::string &x, const std::string string &y )
{
return ( !y.empty() && x.find( y ) != std::string::npos );
}
I would prefer that the function would return false for an empty string.