Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help appending one wchar_t to another! C++

Tags:

c++

I have tried wcscat() but i get a runtime access violation.

wchar_t* a = L"aaa";
wchar_t* b = L"bbb";
wchar_t* c;
c = wcscat(a, b);

Can somebody tell me what is wrong here? Or another way to solve my problem? Thanks


1 Answers

wcscat doesn't create a new string - it simply appends b to a. So, if you want to make sure you don't cause a runtime access violation, you need to make sure there's space for b at the end of a. In the case above:

wchar_t a[7] = L"aaa";
wchar_t b[]  = L"bbb";
wchar_t* c;
c = wcscat(a, b);

You can still get a return value from the function, but it will simply return a.

like image 184
Samir Talwar Avatar answered Sep 05 '25 00:09

Samir Talwar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!