std::strcat(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

okay so welcome to std::strcat(3) from the C++ Standard Libary β€” yes, that's the header's spelling, not mine πŸ’€ β€” this is the group chat for the string-appending icon itself πŸ’–

πŸŽ€ NAME πŸŽ€

std::strcat β€” std::strcat (the main character, literally)

🌸 Synopsis 🌸

Defined in header <cstring>

char* strcat( char* dest, const char* src );

Appends a copy of the character string pointed to by src to the end of the character string pointed to by dest. The character src[0] replaces the null terminator at the end of dest. The resulting byte string is null-terminated. ✨

🚨 undefined behavior alert: the behavior is undefined if the destination array is not large enough for the contents of both src and dest and the terminating null character. Also undefined if the strings overlap. no cap, do not do this πŸ™ˆ

πŸ¦‹ Parameters πŸ¦‹

  • dest β€” pointer to the null-terminated byte string to append to
  • src β€” pointer to the null-terminated byte string to copy from

πŸŽ€ Return value πŸŽ€

dest β€” that's it, that's the return value, bestie πŸ’…

⭐ Notes ⭐

Because strcat needs to seek to the end of dest on each call, it is inefficient to concatenate many strings into one using strcat. like, it's giving "works but not the vibe for a huge pile of strings" 😭

πŸ“ Example πŸ“

        // Run this code

        #include <cstdio>
        #include <cstring>

        int main()
        {
            char str[50] = "Hello ";
            char str2[50] = "World!";
            std::strcat(str, str2);
            std::strcat(str, " Goodbye World!");
            std::puts(str);
        }

🌈 Output 🌈

        Hello World! Goodbye World!

πŸ’œ See also πŸ’œ

  • strncat β€” concatenates a certain amount of characters of two strings (function)
  • strcpy β€” copies one string to another (function)
  • C documentation for strcat

πŸ’– okay that's the whole page, bestie! source/version shoutout: http://cppreference.com, dated 2024.06.10, for std::strcat(3) β€” bye, slay, periodt βœ¨πŸ’…

πŸ“¦ where this page comes from