Search code examples
c++visual-studio-2008mfcconsole-applicationcstring

Using CString to Convert int and Send to Console


My console application attempts to write an integer to the console:

int i = 170;
CString cs;
cs.Format( L"%d", i );
wcout << cs << endl;

I expect "170" to be written to the console, but what happens is "00E21280". This is the address. I have verified that "170" is saved at that memory location. Any ideas?


Solution

  • You have to cast it to a string, otherwise it treats it as a pointer.

    wcout << (PCTSTR)cs << endl;