std::strncat(3)
std::strncat
okay so this is the std::strncat(3) page from the C++ Standard Libary, and bestie, we are gonna get you comfy with it πβ¨
π NAME π
std::strncat - std::strncat (yes, that is literally the whole name, and honestly? iconic π
)
π Synopsis π
Defined in header <cstring> π
char* strncat( char* dest, const char* src, std::size_t count );
Appends the byte string pointed to by src to the byte string pointed to by dest. At most count characters are copied. The resulting byte string is null-terminated. π¦
The destination byte string must have enough space for the contents of both dest and src plus the terminating null character, except that the size of src is limited to count. This is the part where you double-check your buffer, bestie β no cap.
π¨ Undefined behavior alert: the behavior is undefined if the strings overlap. Like, not "oopsie" undefined β actually undefined. π
π«Ά Parameters π«Ά
destβ pointer to the null-terminated byte string to append tosrcβ pointer to the null-terminated byte string to copy fromcountβ maximum number of characters to copy
π Return value π
dest β¨
That's it. That's the return value. She gives you back the destination pointer, main character energy only. π
π§ Notes π§
Because std::strncat needs to seek to the end of dest on each call, it is inefficient to concatenate many strings into one using std::strncat. Like, it works, but it's giving "walking to the end of the line every single time" energy. π
πΈ Example πΈ
// Run this code
#include <cstdio>
#include <cstring>
int main()
{
char str[50] = "Hello ";
const char str2[50] = "World!";
std::strcat(str, str2);
std::strncat(str, " Goodbye World!", 3); // may issue "truncated output" warning
std::puts(str);
}
β Output β
Hello World! Go
π¦ See also π¦
strcatβ concatenates two strings (function)strcpyβ copies one string to another (function)- C documentation for
strncat
mwah π your girl is signing off from the std::strncat(3) page β source: http://cppreference.com, version/date: 2024.06.10 ππ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms