Strstr - C++ Reference

cplusplus.com
  • TUTORIALS
  • REFERENCE
  • ARTICLES
  • FORUM

C++

  • Tutorials
  • Reference
  • Articles
  • Forum

Reference

  • C library:

    • <cassert> (assert.h)
    • <cctype> (ctype.h)
    • <cerrno> (errno.h)
    • C++11 <cfenv> (fenv.h)
    • <cfloat> (float.h)
    • C++11 <cinttypes> (inttypes.h)
    • <ciso646> (iso646.h)
    • <climits> (limits.h)
    • <clocale> (locale.h)
    • <cmath> (math.h)
    • <csetjmp> (setjmp.h)
    • <csignal> (signal.h)
    • <cstdarg> (stdarg.h)
    • C++11 <cstdbool> (stdbool.h)
    • <cstddef> (stddef.h)
    • C++11 <cstdint> (stdint.h)
    • <cstdio> (stdio.h)
    • <cstdlib> (stdlib.h)
    • <cstring> (string.h)
    • C++11 <ctgmath> (tgmath.h)
    • <ctime> (time.h)
    • C++11 <cuchar> (uchar.h)
    • <cwchar> (wchar.h)
    • <cwctype> (wctype.h)
  • Containers:

    • C++11 <array>
    • <deque>
    • C++11 <forward_list>
    • <list>
    • <map>
    • <queue>
    • <set>
    • <stack>
    • C++11 <unordered_map>
    • C++11 <unordered_set>
    • <vector>
  • Input/Output:

    • <fstream>
    • <iomanip>
    • <ios>
    • <iosfwd>
    • <iostream>
    • <istream>
    • <ostream>
    • <sstream>
    • <streambuf>
  • Multi-threading:

    • C++11 <atomic>
    • C++11 <condition_variable>
    • C++11 <future>
    • C++11 <mutex>
    • C++11 <thread>
  • Other:

    • <algorithm>
    • <bitset>
    • C++11 <chrono>
    • C++11 <codecvt>
    • <complex>
    • <exception>
    • <functional>
    • C++11 <initializer_list>
    • <iterator>
    • <limits>
    • <locale>
    • <memory>
    • <new>
    • <numeric>
    • C++11 <random>
    • C++11 <ratio>
    • C++11 <regex>
    • <stdexcept>
    • <string>
    • C++11 <system_error>
    • C++11 <tuple>
    • C++11 <type_traits>
    • C++11 <typeindex>
    • <typeinfo>
    • <utility>
    • <valarray>

<cstring> (string.h)

  • functions

    • memchr
    • memcmp
    • memcpy
    • memmove
    • memset
    • strcat
    • strchr
    • strcmp
    • strcoll
    • strcpy
    • strcspn
    • strerror
    • strlen
    • strncat
    • strncmp
    • strncpy
    • strpbrk
    • strrchr
    • strspn
    • strstr
    • strtok
    • strxfrm
  • types

    • size_t
  • macro constants

    • NULL
  • Reference
  • <cstring>
  • strstr
function <cstring> strstr const char * strstr ( const char * str1, const char * str2 ); char * strstr ( char * str1, const char * str2 ); Locate substring Returns a pointer to the first occurrence of str2 in str1, or a null pointer if str2 is not part of str1. The matching process does not include the terminating null-characters, but it stops there.

Parameters

str1 C string to be scanned. str2 C string containing the sequence of characters to match.

Return Value

A pointer to the first occurrence in str1 of the entire sequence of characters specified in str2, or a null pointer if the sequence is not present in str1.

Portability

In C, this function is only declared as: char * strstr ( const char *, const char * ); instead of the two overloaded versions provided in C++.

Example

1234567891011121314 /* strstr example */ #include <stdio.h> #include <string.h> int main () { char str[] ="This is a simple string"; char * pch; pch = strstr (str,"simple"); if (pch != NULL) strncpy (pch,"sample",6); puts (str); return 0; }
This example searches for the "simple" substring in str and replaces that word for "sample". Output:
This is a sample string

See also

strspnGet span of character set in string (function)strpbrkLocate characters in string (function)strchrLocate first occurrence of character in string (function) Home page | Privacy policy© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s Spotted an error? contact us

Từ khóa » Thư Viện Cstring C++