| Localization library | |||||||||||||||||||||||||
| Regular expressions library(C++11) | |||||||||||||||||||||||||
| Formatting library(C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Functions | ||||||||||||||||||||||||||||||||||||
| Character classification | ||||||||||||||||||||||||||||||||||||
| Character manipulation | ||||||||||||||||||||||||||||||||||||
| Conversions to numeric formats | ||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||
| String manipulation | ||||||||||||||||||||||||||||||||||||
| String examination | ||||||||||||||||||||||||||||||||||||
| Character array functions | ||||||||||||||||||||||||||||||||||||
| Miscellaneous | ||||||||||||||||||||||||||||||||||||
Defined in header <cstring> | ||
constchar* strstr(constchar* haystack,constchar* needle); | ||
char* strstr( char* haystack,constchar* needle); | ||
Finds the first occurrence of the byte stringneedle in the byte string pointed to byhaystack. The terminating null characters are not compared.
Contents |
| haystack | - | pointer to the null-terminated byte string to examine |
| needle | - | pointer to the null-terminated byte string to search for |
Pointer to the first character of the found substring inhaystack, or a null pointer if no such character is found. Ifneedle points to an empty string,haystack is returned.
#include <cstring>#include <iomanip>#include <iostream> int main(){constchar* str="Try not. Do, or do not. There is no try.";constchar* target="not"; for(constchar* result= str;(result= std::strstr(result, target));++result)std::cout<<"Found "<<std::quoted(target)<<" starting at ("<< result- str<<"): "<<std::quoted(result)<<'\n';}
Output:
Found "not" starting at (4): "not. Do, or do not. There is no try."Found "not" starting at (19): "not. There is no try."
| finds the first occurrence of the given substring (public member function of std::basic_string<CharT,Traits,Allocator>)[edit] | |
| finds the first occurrence of a wide string within another wide string (function)[edit] | |
| finds the first occurrence of a character (function)[edit] | |
| finds the last occurrence of a character (function)[edit] | |
C documentation forstrstr | |