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.
views:
356answers:
4
+3
A:
#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.
Brendan
2009-12-06 17:34:01
It has been declared deprecated.
Chad
2009-12-06 17:49:49
+4
A:
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*.
Georg Fritzsche
2009-12-06 18:06:02
or `const wchar_t * concatenation = s.c_str();` depending -- but yes the first thing I'd do is wrap them in a string type.
Steve Gilham
2009-12-06 18:08:34
A:
Mike Weller
2009-12-06 18:56:25