I have two variables that are LPCWSTR
s. I want to create a new variable that will have the values of the first and second variable.
I tried this but it didn't work.
LPCWSTR d = L"sd";
LPCWSTR f = L"f";
LPCWSTR df = d + f;
I get this error when i try that.
1 IntelliSense: expression must have integral or enum type
Is there a function that can combine two LPCWSTR
s?
In C++ it is usually a good idea to use std::string
for manipulations with strings. In your case it could look like:
LPCWSTR d = L"sd";
LPCWSTR f = L"f";
std::wstring df = std::wstring(d) + f;
LPCWSTR dfc = df.c_str(); // if you are really need this
It doesn't work because the C++ compiler cannot generate code to join together arrays. The two strings in the example are arrays of type wchar_t. To join arrays you must use higher level functions. There are several ways of doing it:
LPWSTR df[20]; // cannot be LPCWSTR, because the C is for const.
wcsprintf(df, L"%s%s", d, f);
or
LPWSTR df[20];
wcscpy(df, d);
wcscat(df, f);
or use STL as previously answered.
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