Click here to Skip to main content
15,916,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I just wrote this code to concatenate two wide characters strings. Could someone please comment if it looks OK? (seems to work at least).

1. SomeStringClass amount = Window->get_text();
2. wchar_t strAmount[100] = L"Amount: "; // I know I could remove 100 from here too
3. wchar_t *ptr = wcscat( strAmount, amount.c_str() );
4.  SomeStringClass  finalStr;
5. finalStr.set(ptr, 10 /* 10 is roughly due to length of Amount line 2*/ + amount.length());

Now, finalStr contains what I wanted, e.g., "Amount: 123"
Updated 23-May-13 1:43am
Mohibur Rashid 23-May-13 7:50am    
if you are using MFC
then try CString amount=...
CString strAmout=L"Amount : "
CString finalStr;
finalStr.Format("%s%d", strAmou, amount);
Dan page 23-May-13 8:13am    
no, it's not MFC
CPallini 23-May-13 8:12am    
Looks a lot of unnecessary code. For instance, what's the usefulness of the amount variable?
Dan page 23-May-13 8:13am    
it's there to retrieve value of amount entered by user on display
CPallini 23-May-13 8:19am    
Well, you may use directly Window->get_text() result, right?

1 solution

SomeStringClass amount = Window->get_text();
wchar_t strAmount[100];
int swprintf(strAmount, L"Amount: %s", amount);
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