std::wcscat(3)

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

πŸ’… NAME πŸ’…

ok so this is the std::wcscat(3) page, and it lives in the C++ Standard Library β€” yeah, the whole big C++ thing. and the function itself is, iconic behaviour, literally called std::wcscat. we love a page that names itself. slay.


✨ Synopsis ✨

first things first, bestie, it's defined in header <cwchar> πŸ“Œ like that's where it lives, that's its home.

wchar_t* wcscat( wchar_t* dest, const wchar_t* src );

ok so what does it do: it takes a copy of the wide string that src points at and appends it to the end of the wide string that dest points at. and the way it pulls that off? the wide character src[0] straight up replaces the null terminator sitting at the end of dest. bold move honestly. and the resulting wide string? null-terminated, obviously. we stay tidy. πŸŽ€

GIRL. LISTEN. the behaviour is undefined if the destination array isn't big enough to hold the contents of both src and dest plus the terminating null wide character. like, undefined undefined. no cap. πŸ’€
also undefined: the behaviour if the strings overlap. do not do the overlapping thing. it's giving disaster. πŸ™ˆ

🌸 Parameters 🌸

  • dest β€” pointer to the null-terminated wide string you're appending to. the main character, the one getting stuff added πŸ’–
  • src β€” pointer to the null-terminated wide string you're copying from. the contributor. the guest star. πŸ¦‹

πŸ‘‘ Return value πŸ‘‘

it returns a copy of dest. that's it, that's the return. cute, simple, gives you back what you handed it. 🫢


🌈 Example 🌈

// Run this code

#include <clocale>
#include <cwchar>
#include <iostream>

int main(void)
{
    wchar_t str[50] = L"ЗСмля, ΠΏΡ€ΠΎΡ‰Π°ΠΉ.";
    std::wcscat(str, L" ");
    std::wcscat(str, L"Π’ Π΄ΠΎΠ±Ρ€Ρ‹ΠΉ ΠΏΡƒΡ‚ΡŒ.");

    std::setlocale(LC_ALL, "en_US.utf8");
    std::wcout.imbue(std::locale("en_US.utf8"));
    std::wcout << str << '\n';
}

Possible output:

ЗСмля, ΠΏΡ€ΠΎΡ‰Π°ΠΉ. Π’ Π΄ΠΎΠ±Ρ€Ρ‹ΠΉ ΠΏΡƒΡ‚ΡŒ.

look at that. two std::wcscat calls and a space in between and the string is built. we love to see it. the std::setlocale(LC_ALL, "en_US.utf8") and std::wcout.imbue(std::locale("en_US.utf8")) lines are there so the wide characters actually print properly β€” thoughtful king behaviour. πŸ”₯


⭐ See also ⭐

  • wcsncat β€” appends a certain amount of wide characters from one wide string to another (function) β€” the "I only want some of it" version πŸ’œ
  • strcat β€” concatenates two strings (function) β€” same energy but the narrow-char edition πŸ“
  • wcscpy β€” copies one wide string to another (function) β€” no appending, just a straight copy gig 🧚
  • C documentation for wcscat β€” the og C version, for when you wanna cross-reference πŸ“š

ok that's the whole page bestie, you're officially a std::wcscat expert, iykyk πŸ’…βœ¨

made with love on cppreference.com, version 2024.06.10 β€” mwah, go forth and concatenate responsibly πŸŽ€
πŸ“¦ where this page comes from