The strstr() function in C++ cstring strstr() is part of the C-string library
Syntax:
char* strstr(const char* haystack, const char* needle);
Parameters:
haystack: The string to be searched.
needle: The substring to search for within haystack.
Example Usage:
#include
#include
int main() {
const char* text = "Hello, welcome to the world of C++ programming.";
const char* search = "C++";
char* result = strstr(text, search);
if (result != nullptr) {
std::cout << "Substring found at: " << result << std::endl;
} else {
std::cout << "Substring not found." << std::endl;
}
return 0;
}
Key Points:
strstr() is case-sensitive.
Returns a pointer to the first occurrence of the substring or nullptr if not found.