Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, is there a way to add two LPWSTR and the result will also be LPWSTR ?

like...
C++
LPWSTR str1 = L"Hello ";
LPWSTR str2 = L"World";

LPWSTR str3 = str1 + str2;

MessageBoxW(0, str3, L"title", 0);
Posted
Updated 30-Mar-20 7:39am

You don't do it with plus!

You need wcsncat: http://msdn.microsoft.com/en-us/library/tbyd7s1y.aspx[^]
 
Share this answer
 
Comments
Member 13593880 2-Jan-18 14:38pm    
what is reason with plus operator with

LPWSTR str1 = L"Hello ";
LPWSTR str2 = L"World";
LPWSTR str3 = str1 + str2;
MessageBoxW(0, str3, L"title", 0);
Member 13593880 2-Jan-18 14:39pm    
why above is not running
OriginalGriff 3-Jan-18 2:24am    
Because adding pointers is meaningless.
Think of a pointer as a phone number: If I add your phone number to mine, what do I get? Who do I speak to if I dial that?
Pointers are the same thing - you can't add them together and expect to get a string result.
Adding the pointers that way is just a mistake. Adding two wstring objects makes the magic:
C++
#include <string>
#include <iostream>
#include <Windows.h>

using namespace std;
int main()
{
    LPWSTR str1 = L"Hello ";
    LPWSTR str2 = L"World";

    wstring w1(str1);
    wstring w2(str2);
    wstring w3 = w1+w2;
    wcout << w3 << endl;
}
 
Share this answer
 
Comments
Member 13593880 2-Jan-18 14:39pm    
what is reason with plus operator with

LPWSTR str1 = L"Hello ";
LPWSTR str2 = L"World";
LPWSTR str3 = str1 + str2;
MessageBoxW(0, str3, L"title", 0);
Member 11469095 30-Mar-20 13:43pm    
LPWSTR str1 = L"Hello ";
LPWSTR str2 = L"World";
wstring w1(str1);
wstring w2(str2);
wstring w3 = w1 + w2;
MessageBoxW(0, w3.c_str(), L"title", 0);
try with the concept of string concatenation.
we have strcat and some more methods to concatenate two strings.
Please have a look at that once.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900