Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/string/wide/wcsncat"

From cppreference.com
< cpp‎ | string‎ | wide
m (Text replace - "dcl list str" to "dcl list wcs")
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/sidebar}}
+
{{cpp/string/wide/navbar}}
{{ddcl | header=cstring |
+
{{ddcl|header=cwchar|
char *strncat( char *dest, const char *src, size_t count );
+
wchar_t* wcsncat( wchar_t* dest, const wchar_t* src, std::size_t count );
 
}}
 
}}
  
Appends a character string pointed to by {{tt|src}} to a character string pointed to by {{tt|dest}}. At most {{tt|count}} characters are copied. The resulting character string is null-terminated. If the strings overlap, the behavior is undefined.  
+
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===
{{param list begin}}
+
{{par begin}}
{{param list item | dest | pointer to the null-terminated character string to append to}}
+
{{par|dest|pointer to the null-terminated wide string to append to}}
{{param list item | src | pointer to the null-terminated character string to copy from}}
+
{{par|src|pointer to the null-terminated wide string to copy from}}
{{param list item | count | maximum number of characters to copy}}
+
{{par|count|maximum number of wide characters to copy}}
{{param list end}}
+
{{par end}}
  
 
===Return value===
 
===Return value===
 
+
{{c|dest}}
{{tt|dest}}
+
  
 
===Example===
 
===Example===
{{example cpp
+
{{example
|
+
|code=
  | code=
+
#include <clocale>
| output=
+
#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===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list template | cpp/string/narrow/dcl list wcscat}}
+
{{dsc inc|cpp/string/wide/dsc wcscat}}
{{dcl list template | cpp/string/narrow/dcl list wcscpy}}
+
{{dsc inc|cpp/string/byte/dsc strncat}}
{{dcl list end}}
+
{{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

#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) [edit]
concatenates a certain amount of characters of two strings
(function) [edit]
copies one wide string to another
(function) [edit]
C documentation for wcsncat