Difference between revisions of "cpp/string/wide/wcsncat"
From cppreference.com
m (Text replace - "dcl list str" to "dcl list wcs") |
Andreas Krug (Talk | contribs) m (wchar_t * -> wchar_t*) |
||
(12 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{cpp/title| wcsncat}} | {{cpp/title| wcsncat}} | ||
− | {{cpp/string/wide/ | + | {{cpp/string/wide/navbar}} |
− | {{ddcl | header= | + | {{ddcl|header=cwchar| |
− | + | wchar_t* wcsncat( wchar_t* dest, const wchar_t* src, std::size_t count ); | |
}} | }} | ||
− | Appends | + | Appends at most {{c|count}} wide characters from the wide string pointed to by {{c|src}} to the end of the character string pointed to by {{c|dest}}, stopping if the null terminator is copied. The wide character {{c|src[0]}} replaces the null terminator at the end of {{c|dest}}. The null terminator is always appended in the end (so the maximum number of wide characters the function may write is {{c|count + 1}}). |
+ | |||
+ | The behavior is undefined if the destination array is not large enough for the contents of both {{c|src}} and {{c|dest}} and the terminating null wide character. | ||
+ | |||
+ | The behavior is undefined if the strings overlap. | ||
===Parameters=== | ===Parameters=== | ||
− | {{ | + | {{par begin}} |
− | {{ | + | {{par|dest|pointer to the null-terminated wide string to append to}} |
− | {{ | + | {{par|src|pointer to the null-terminated wide string to copy from}} |
− | {{ | + | {{par|count|maximum number of wide characters to copy}} |
− | {{ | + | {{par end}} |
===Return value=== | ===Return value=== | ||
− | + | {{c|dest}} | |
− | {{ | + | |
===Example=== | ===Example=== | ||
− | {{example | + | {{example |
− | + | |code= | |
− | | | + | #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'; | ||
+ | } | ||
+ | |p=true | ||
+ | |output= | ||
+ | Земля, прощай. В добрый | ||
}} | }} | ||
===See also=== | ===See also=== | ||
− | {{ | + | {{dsc begin}} |
− | {{ | + | {{dsc inc|cpp/string/wide/dsc wcscat}} |
− | {{ | + | {{dsc inc|cpp/string/byte/dsc strncat}} |
− | {{ | + | {{dsc inc|cpp/string/wide/dsc wcscpy}} |
+ | {{dsc see c|c/string/wide/wcsncat}} | ||
+ | {{dsc end}} | ||
+ | |||
+ | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} |
Latest revision as of 03:47, 22 October 2023
Defined in header <cwchar>
|
||
wchar_t* wcsncat( wchar_t* dest, const wchar_t* src, std::size_t count ); |
||
Appends at most count wide characters from the wide string pointed to by src to the end of the character string pointed to by dest, stopping if the null terminator is copied. The wide character src[0] replaces the null terminator at the end of dest. The null terminator is always appended in the end (so the maximum number of wide characters the function may write is count + 1).
The behavior is undefined if the destination array is not large enough for the contents of both src and dest and the terminating null wide character.
The behavior is undefined if the strings overlap.
Contents |
[edit] Parameters
dest | - | pointer to the null-terminated wide string to append to |
src | - | pointer to the null-terminated wide string to copy from |
count | - | maximum number of wide characters to copy |
[edit] Return value
dest
[edit] Example
Run this code
#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:
Земля, прощай. В добрый
[edit] See also
appends a copy of one wide string to another (function) | |
concatenates a certain amount of characters of two strings (function) | |
copies one wide string to another (function) | |
C documentation for wcsncat
|