CEdit * pedit;
ostringstream fos;
std::wstring element;
std::Cstring Svalue = "hello";
pedit = (CEdit *) GetDlgItem(CE_BOX);
fos << setw(2) << setfill('0') << hex << (int) Svalue; //
element = fos.str().c_str(); // First error HERE.
pedit->SetWindowText(element); // Second error HERE
But i get several errors:
1. in line (First error HERE): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const char *' (or there is no acceptable conversion)
2. in line (Second error HERE): error C2664: 'CWnd::SetWindowTextW' : cannot convert parameter 1 from 'std::wstring' to 'LPCTSTR'.
With regards to the use of cstring::format(), it seems to me that if I change now the code i will get the same error as the second line one.
You can't pass a std::wstring as argument to CEdit->SetWindowText, as you are trying to do. Use c_str() member as this: pedit->SetWindowText(element.c_str()); // Second error HERE
As for the first error, you cannot use const char* as argument of std::wstring constructor, as you do in this line: element = fos.str().c_str(); // First error HERE.
fos is a ostringstream type, but you need to be of type wostringstream
First of all, i need to say that my vs2010 project had an UNICODE Character set (checked in project-> properties-> general). I have now changed this to Multibyte Character set.
So considering the above, i have considered changing the program following the suggestions from modoran, that is, i use the MFC style to using CString::Format().
So in order to achieve this my code would be as follows: