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> | ||
char* strncat(char* dest,constchar* src,std::size_t count); | ||
Appends a byte string pointed to bysrc to a byte string pointed to bydest. At mostcount characters are copied. The resulting byte string is null-terminated.
The destination byte string must have enough space for the contents of bothdest andsrc plus the terminating null character, except that the size ofsrc is limited tocount.
The behavior is undefined if the strings overlap.
Contents |
dest | - | pointer to the null-terminated byte string to append to |
src | - | pointer to the null-terminated byte string to copy from |
count | - | maximum number of characters to copy |
dest
Becausestd::strncat
needs to seek to the end ofdest on each call, it is inefficient to concatenate many strings into one usingstd::strncat
.
#include <cstdio>#include <cstring> int main(){char str[50]="Hello ";constchar str2[50]="World!";std::strcat(str, str2); std::strncat(str," Goodbye World!",3);// may issue "truncated output" warningstd::puts(str);}
Output:
Hello World! Go
concatenates two strings (function)[edit] | |
copies one string to another (function)[edit] | |
C documentation forstrncat |