I have a base wchar_t*
and I'm looking to append another one onto the end. How do I do it? I cannot use deprecated functions as I am treating warnings as errors.
The strcat() method is used to concatenate strings in C++. The strcat() function takes char array as input and then concatenates the input values passed to the function. In the above example, we have declared two char arrays mainly str1 and str2 of size 100 characters.
Concatenation is the process of appending one string to the end of another string. You concatenate strings by using the + operator.
Description. The wcscat() function appends a copy of the string pointed to by string2 to the end of the string pointed to by string1. The wcscat() function operates on null-ended wchar_t strings. The string arguments to this function should contain a wchar_t null character marking the end of the string.
In formal language theory and computer programming, string concatenation is the operation of joining character strings end-to-end. For example, the concatenation of "snow" and "ball" is "snowball".
Why not use a std::wstring
in the first place:
wchar_t *ws1 = foo(), *ws2 = bar();
std::wstring s(ws1);
s += std::wstring(ws2);
std::wcout << s << std::endl;
If needed, std::wstring::c_str()
gives you access to the result as a const wchar_t*
.
#include <wchar.h>
wchar_t *wcsncat(wchar_t *ws1, const wchar_t *ws2, size_t n);
The wcsncat()
function appends no more than the first n characters of the string pointed to by ws2
to the end of the string pointed to by ws1
. If a NULL
character appears in ws2
before n
characters, all characters up to the NULL
character are appended to ws1
. The first character of ws2
overwrites the terminating NULL
character of ws1
. A NULL
terminating character is always appended to the result, and if the objects used for copying overlap, the behavior is undefined.
ws1
Is the null-terminated destination string.
ws2
Is the null-terminated source string.
n
Is the number of characters to append.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With