std::wcsncat(3)
๐ std::wcsncat
okay bestie, welcome to the std::wcsncat page from the C++ Standard Library โ she's a little wide-string appender and honestly she ate ๐
โจ NAME โจ
std::wcsncat โ yes that's literally it, the name is the name, we love a self-titled icon ๐
๐ธ Synopsis ๐ธ
She lives in the header <cwchar>, as all the wide-char girlies do:
wchar_t* wcsncat( wchar_t* dest, const wchar_t* src, std::size_t count );
So here's the vibe check: she appends at most count wide characters from the wide string pointed to by src onto the end of the character string pointed to by dest โ and she stops early if the null terminator gets copied. ๐
The way that src[0] just replaces the null terminator sitting at the end of destโฆ main character energy, fr fr.
And the null terminator? Always appended at the end, no exceptions. So the maximum number of wide characters this function may write is count + 1. Math girlie. ๐งฎโจ
โ ๏ธ Lowkey important, ngl: the behavior is undefined if the destination array isn't large enough to hold the contents of bothsrcanddestplus the terminating null wide character. Like, she will not check for you. She trusts you. Do not betray her. ๐ญ
โ ๏ธ Also undefined if the strings overlap. Justโฆ don't. ๐
๐ Parameters ๐
destโ pointer to the null-terminated wide string you're appending to ๐ซถsrcโ pointer to the null-terminated wide string you're copying from ๐countโ the maximum number of wide characters to copy, like a little limit, a lil snack portion ๐
๐ Return value ๐
She gives you back dest. That's it. That's the return. Simple. Iconic. Periodt. ๐
๐ฆ Example ๐ฆ
Run this code, bestie:
#include <clocale>
#include <cwchar>
#include <iostream>
int main(void)
{
wchar_t str[50] = L"ะะตะผะปั, ะฟัะพัะฐะน.";
std::wcsncat(str, L" ", 1);
std::wcsncat(str, L"ะ ะดะพะฑััะน ะฟััั.", 8); // only append the first 8 wide chars
std::setlocale(LC_ALL, "en_US.utf8");
std::wcout.imbue(std::locale("en_US.utf8"));
std::wcout << str << '\n';
}
Possible output:
ะะตะผะปั, ะฟัะพัะฐะน. ะ ะดะพะฑััะน
See how she only grabbed the first 8 wide chars on that second call? Limited edition behavior, and we're obsessed. ๐ โจ
๐ฅ See also ๐ฅ
wcscatโ appends a copy of one wide string to another (function)strncatโ concatenates a certain amount of characters of two strings (function)wcscpyโ copies one wide string to another (function)- C documentation for
wcsncatโ the OG, the ancestor, the blueprint ๐
๐ okay that's the whole page, bestie! This gem came from http://cppreference.com, dated 2024.06.10, and it's the std::wcsncat(3) manual page โ go forth and append responsibly, and remember: the array must be big enough or it's undefined behavior city ๐ญ๐ซถโจ
๐ฆ 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