#include#include using namespace std; int main() { string str = "Hello, World!"; string prefix = "Hello"; bool startsWith = str.startsWith(prefix); if (startsWith) { cout << "The string starts with prefix." << endl; } else { cout << "The string does not starts with prefix." << endl; } return 0; }
The string starts with prefix.
#include#include using namespace std; int main() { string str = "Hello, World!"; string prefix = "Bye"; bool startsWith = str.startsWith(prefix); if (startsWith) { cout << "The string starts with prefix." << endl; } else { cout << "The string does not starts with prefix." << endl; } return 0; }
The string does not starts with prefix.The String StartsWith function is a part of the C++ Standard Library.