Use std::string::find
as follows:
if (s1.find(s2) != std::string::npos) {
std::cout << "found!" << '\n';
}
Note: “found!” will be printed if s2
is a substring of s1
, both s1
and s2
are of type std::string
.
More Related Contents:
- Replace part of a string with another string
- Replace substring with another substring C++
- How do I check if a C++ std::string starts with a certain string, and convert a substring to an int?
- C++ string::find complexity
- How to use string.substr() function?
- How to remove all substrings from a string
- What is the type of string literals in C and C++?
- Meaning of acronym SSO in the context of std::string
- What is the fastest substring search algorithm?
- No matching function – ifstream open()
- Why is strncpy insecure?
- How to convert string to char array in C++?
- How to convert std::string to LPCSTR?
- What makes more sense – char* string or char *string? [duplicate]
- C/C++: Optimization of pointers to string constants
- Why does C++ allow an integer to be assigned to a string?
- Proper way to copy C strings
- Why are strings in C++ usually terminated with ‘\0’?
- invalid conversion from ‘const char*’ to ‘char’
- String to enum in C++
- writing directly to std::string internal buffers
- What is the proper function for comparing two C-style strings?
- C++: Can a macro expand “abc” into ‘a’, ‘b’, ‘c’?
- Converting bool to text in C++
- Do I have to use #include beside ?
- Extract only right most n letters from a string
- Fastest way to Convert String to Binary?
- Concatenate compile-time strings in a template at compile time?
- C++ most efficient way to convert string to int (faster than atoi)
- How do I include the string header?