23 Strings library [strings]

23.5 Null-terminated sequence utilities [c.strings]

23.5.1 Header <cctype> synopsis [cctype.syn]

namespace std { int isalnum(int c); int isalpha(int c); int isblank(int c); int iscntrl(int c); int isdigit(int c); int isgraph(int c); int islower(int c); int isprint(int c); int ispunct(int c); int isspace(int c); int isupper(int c); int isxdigit(int c); int tolower(int c); int toupper(int c); }
The contents and meaning of the header <cctype> are the same as the C standard library header <ctype.h>.
See also: ISO/IEC 9899:2018, 7.4

23.5.2 Header <cwctype> synopsis [cwctype.syn]

namespace std { using wint_t = see below; using wctrans_t = see below; using wctype_t = see below; int iswalnum(wint_t wc); int iswalpha(wint_t wc); int iswblank(wint_t wc); int iswcntrl(wint_t wc); int iswdigit(wint_t wc); int iswgraph(wint_t wc); int iswlower(wint_t wc); int iswprint(wint_t wc); int iswpunct(wint_t wc); int iswspace(wint_t wc); int iswupper(wint_t wc); int iswxdigit(wint_t wc); int iswctype(wint_t wc, wctype_t desc); wctype_t wctype(const char* property); wint_t towlower(wint_t wc); wint_t towupper(wint_t wc); wint_t towctrans(wint_t wc, wctrans_t desc); wctrans_t wctrans(const char* property); } #define WEOF see below
The contents and meaning of the header <cwctype> are the same as the C standard library header <wctype.h>.
See also: ISO/IEC 9899:2018, 7.30

23.5.3 Header <cstring> synopsis [cstring.syn]

namespace std { using size_t = see [support.types.layout]; void* memcpy(void* s1, const void* s2, size_t n); void* memmove(void* s1, const void* s2, size_t n); char* strcpy(char* s1, const char* s2); char* strncpy(char* s1, const char* s2, size_t n); char* strcat(char* s1, const char* s2); char* strncat(char* s1, const char* s2, size_t n); int memcmp(const void* s1, const void* s2, size_t n); int strcmp(const char* s1, const char* s2); int strcoll(const char* s1, const char* s2); int strncmp(const char* s1, const char* s2, size_t n); size_t strxfrm(char* s1, const char* s2, size_t n); const void* memchr(const void* s, int c, size_t n); // see [library.c] void* memchr(void* s, int c, size_t n); // see [library.c] const char* strchr(const char* s, int c); // see [library.c] char* strchr(char* s, int c); // see [library.c] size_t strcspn(const char* s1, const char* s2); const char* strpbrk(const char* s1, const char* s2); // see [library.c] char* strpbrk(char* s1, const char* s2); // see [library.c] const char* strrchr(const char* s, int c); // see [library.c] char* strrchr(char* s, int c); // see [library.c] size_t strspn(const char* s1, const char* s2); const char* strstr(const char* s1, const char* s2); // see [library.c] char* strstr(char* s1, const char* s2); // see [library.c] char* strtok(char* s1, const char* s2); void* memset(void* s, int c, size_t n); char* strerror(int errnum); size_t strlen(const char* s); } #define NULL see [support.types.nullptr]
The contents and meaning of the header <cstring> are the same as the C standard library header <string.h>.
The functions strerror and strtok are not required to avoid data races.
The functions memcpy and memmove are signal-safe.
Both functions implicitly create objects ([intro.object]) in the destination region of storage immediately prior to copying the sequence of characters to the destination.
[Note 1: 
The functions strchr, strpbrk, strrchr, strstr, and memchr, have different signatures in this document, but they have the same behavior as in the C standard library.
— end note]
See also: ISO/IEC 9899:2018, 7.24

23.5.4 Header <cwchar> synopsis [cwchar.syn]

namespace std { using size_t = see [support.types.layout]; using mbstate_t = see below; using wint_t = see below; struct tm; int fwprintf(FILE* stream, const wchar_t* format, ...); int fwscanf(FILE* stream, const wchar_t* format, ...); int swprintf(wchar_t* s, size_t n, const wchar_t* format, ...); int swscanf(const wchar_t* s, const wchar_t* format, ...); int vfwprintf(FILE* stream, const wchar_t* format, va_list arg); int vfwscanf(FILE* stream, const wchar_t* format, va_list arg); int vswprintf(wchar_t* s, size_t n, const wchar_t* format, va_list arg); int vswscanf(const wchar_t* s, const wchar_t* format, va_list arg); int vwprintf(const wchar_t* format, va_list arg); int vwscanf(const wchar_t* format, va_list arg); int wprintf(const wchar_t* format, ...); int wscanf(const wchar_t* format, ...); wint_t fgetwc(FILE* stream); wchar_t* fgetws(wchar_t* s, int n, FILE* stream); wint_t fputwc(wchar_t c, FILE* stream); int fputws(const wchar_t* s, FILE* stream); int fwide(FILE* stream, int mode); wint_t getwc(FILE* stream); wint_t getwchar(); wint_t putwc(wchar_t c, FILE* stream); wint_t putwchar(wchar_t c); wint_t ungetwc(wint_t c, FILE* stream); double wcstod(const wchar_t* nptr, wchar_t** endptr); float wcstof(const wchar_t* nptr, wchar_t** endptr); long double wcstold(const wchar_t* nptr, wchar_t** endptr); long int wcstol(const wchar_t* nptr, wchar_t** endptr, int base); long long int wcstoll(const wchar_t* nptr, wchar_t** endptr, int base); unsigned long int wcstoul(const wchar_t* nptr, wchar_t** endptr, int base); unsigned long long int wcstoull(const wchar_t* nptr, wchar_t** endptr, int base); wchar_t* wcscpy(wchar_t* s1, const wchar_t* s2); wchar_t* wcsncpy(wchar_t* s1, const wchar_t* s2, size_t n); wchar_t* wmemcpy(wchar_t* s1, const wchar_t* s2, size_t n); wchar_t* wmemmove(wchar_t* s1, const wchar_t* s2, size_t n); wchar_t* wcscat(wchar_t* s1, const wchar_t* s2); wchar_t* wcsncat(wchar_t* s1, const wchar_t* s2, size_t n); int wcscmp(const wchar_t* s1, const wchar_t* s2); int wcscoll(const wchar_t* s1, const wchar_t* s2); int wcsncmp(const wchar_t* s1, const wchar_t* s2, size_t n); size_t wcsxfrm(wchar_t* s1, const wchar_t* s2, size_t n); int wmemcmp(const wchar_t* s1, const wchar_t* s2, size_t n); const wchar_t* wcschr(const wchar_t* s, wchar_t c); // see [library.c] wchar_t* wcschr(wchar_t* s, wchar_t c); // see [library.c] size_t wcscspn(const wchar_t* s1, const wchar_t* s2); const wchar_t* wcspbrk(const wchar_t* s1, const wchar_t* s2); // see [library.c] wchar_t* wcspbrk(wchar_t* s1, const wchar_t* s2); // see [library.c] const wchar_t* wcsrchr(const wchar_t* s, wchar_t c); // see [library.c] wchar_t* wcsrchr(wchar_t* s, wchar_t c); // see [library.c] size_t wcsspn(const wchar_t* s1, const wchar_t* s2); const wchar_t* wcsstr(const wchar_t* s1, const wchar_t* s2); // see [library.c] wchar_t* wcsstr(wchar_t* s1, const wchar_t* s2); // see [library.c] wchar_t* wcstok(wchar_t* s1, const wchar_t* s2, wchar_t** ptr); const wchar_t* wmemchr(const wchar_t* s, wchar_t c, size_t n); // see [library.c] wchar_t* wmemchr(wchar_t* s, wchar_t c, size_t n); // see [library.c] size_t wcslen(const wchar_t* s); wchar_t* wmemset(wchar_t* s, wchar_t c, size_t n); size_t wcsftime(wchar_t* s, size_t maxsize, const wchar_t* format, const tm* timeptr); wint_t btowc(int c); int wctob(wint_t c); // [c.mb.wcs], multibyte / wide string and character conversion functions int mbsinit(const mbstate_t* ps); size_t mbrlen(const char* s, size_t n, mbstate_t* ps); size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* ps); size_t wcrtomb(char* s, wchar_t wc, mbstate_t* ps); size_t mbsrtowcs(wchar_t* dst, const char** src, size_t len, mbstate_t* ps); size_t wcsrtombs(char* dst, const wchar_t** src, size_t len, mbstate_t* ps); } #define NULL see [support.types.nullptr] #define WCHAR_MAX see below #define WCHAR_MIN see below #define WEOF see below
The contents and meaning of the header <cwchar> are the same as the C standard library header <wchar.h>, except that it does not declare a type wchar_t.
[Note 1: 
The functions wcschr, wcspbrk, wcsrchr, wcsstr, and wmemchr have different signatures in this document, but they have the same behavior as in the C standard library.
— end note]
See also: ISO/IEC 9899:2018, 7.29

23.5.5 Header <cuchar> synopsis [cuchar.syn]

namespace std { using mbstate_t = see below; using size_t = see [support.types.layout]; size_t mbrtoc8(char8_t* pc8, const char* s, size_t n, mbstate_t* ps); size_t c8rtomb(char* s, char8_t c8, mbstate_t* ps); size_t mbrtoc16(char16_t* pc16, const char* s, size_t n, mbstate_t* ps); size_t c16rtomb(char* s, char16_t c16, mbstate_t* ps); size_t mbrtoc32(char32_t* pc32, const char* s, size_t n, mbstate_t* ps); size_t c32rtomb(char* s, char32_t c32, mbstate_t* ps); }
The contents and meaning of the header <cuchar> are the same as the C standard library header <uchar.h>, except that it declares the additional mbrtoc8 and c8rtomb functions and does not declare types char16_t nor char32_t.
See also: ISO/IEC 9899:2018, 7.28

23.5.6 Multibyte / wide string and character conversion functions [c.mb.wcs]

[Note 1: 
The headers <cstdlib>, <cuchar>, and <cwchar> declare the functions described in this subclause.
— end note]
int mbsinit(const mbstate_t* ps); int mblen(const char* s, size_t n); size_t mbstowcs(wchar_t* pwcs, const char* s, size_t n); size_t wcstombs(char* s, const wchar_t* pwcs, size_t n);
Effects: These functions have the semantics specified in the C standard library.
See also: ISO/IEC 9899:2018, 7.22.7.1, 7.22.8, 7.29.6.2.1
int mbtowc(wchar_t* pwc, const char* s, size_t n); int wctomb(char* s, wchar_t wchar);
Effects: These functions have the semantics specified in the C standard library.
Remarks: Calls to these functions may introduce a data race ([res.on.data.races]) with other calls to the same function.
See also: ISO/IEC 9899:2018, 7.22.7
size_t mbrlen(const char* s, size_t n, mbstate_t* ps); size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* ps); size_t wcrtomb(char* s, wchar_t wc, mbstate_t* ps); size_t mbsrtowcs(wchar_t* dst, const char** src, size_t len, mbstate_t* ps); size_t wcsrtombs(char* dst, const wchar_t** src, size_t len, mbstate_t* ps);
Effects: These functions have the semantics specified in the C standard library.
Remarks: Calling these functions with an mbstate_t* argument that is a null pointer value may introduce a data race ([res.on.data.races]) with other calls to the same function with an mbstate_t* argument that is a null pointer value.
See also: ISO/IEC 9899:2018, 7.29.6.3
size_t mbrtoc8(char8_t* pc8, const char* s, size_t n, mbstate_t* ps);
Effects: If s is a null pointer, equivalent to mbrtoc8(nullptr, "", 1, ps).
Otherwise, the function inspects at most n bytes beginning with the byte pointed to by s to determine the number of bytes needed to complete the next multibyte character (including any shift sequences).
If the function determines that the next multibyte character is complete and valid, it determines the values of the corresponding UTF-8 code units and then, if pc8 is not a null pointer, stores the value of the first (or only) such code unit in the object pointed to by pc8.
Subsequent calls will store successive UTF-8 code units without consuming any additional input until all the code units have been stored.
If the corresponding Unicode character is U+0000 null, the resulting state described is the initial conversion state.
Returns: The first of the following that applies (given the current conversion state):
  • 0, if the next n or fewer bytes complete the multibyte character that corresponds to the U+0000 null Unicode character (which is the value stored).
  • between 1 and n (inclusive), if the next n or fewer bytes complete a valid multibyte character (whose first (or only) code unit is stored); the value returned is the number of bytes that complete the multibyte character.
  • (size_t)(-3), if the next code unit resulting from a previous call has been stored (no bytes from the input have been consumed by this call).
  • (size_t)(-2), if the next n bytes contribute to an incomplete (but potentially valid) multibyte character, and all n bytes have been processed (no value is stored).
  • (size_t)(-1), if an encoding error occurs, in which case the next n or fewer bytes do not contribute to a complete and valid multibyte character (no value is stored); the value of the macro EILSEQ is stored in errno, and the conversion state is unspecified.
size_t c8rtomb(char* s, char8_t c8, mbstate_t* ps);
Effects: If s is a null pointer, equivalent to c8rtomb(buf, u8'\0', ps) where buf is an internal buffer.
Otherwise, if c8 completes a sequence of valid UTF-8 code units, determines the number of bytes needed to represent the multibyte character (including any shift sequences), and stores the multibyte character representation in the array whose first element is pointed to by s.
At most MB_CUR_MAX bytes are stored.
If the multibyte character is a null character, a null byte is stored, preceded by any shift sequence needed to restore the initial shift state; the resulting state described is the initial conversion state.
Returns: The number of bytes stored in the array object (including any shift sequences).
If c8 does not contribute to a sequence of char8_t corresponding to a valid multibyte character, the value of the macro EILSEQ is stored in errno, (size_t) (-1) is returned, and the conversion state is unspecified.
Remarks: Calls to c8rtomb with a null pointer argument for s may introduce a data race ([res.on.data.races]) with other calls to c8rtomb with a null pointer argument for s.