C++ newbie here with a quick question. How do I print the contents of CString to the Console?
Doing this
int main(array<System::String ^> ^args)
{
CString cs1 = _T("Hy");
CString cs2 = _T(" u");
CString cs3 = cs1 + cs2;
Console::WriteLine(cs3);
printf("%s", cs3);
return 0;
}
outputs "True" and "H" on the console. TIA.
I'm guessing you're compiling with Unicode turned on, but printf
is an ANSI function, so it prints only the first character of the string. Use _tprintf
to match your _T
strings:
_tprintf(_T("%s"), cs3);
Console::WriteLine(gcnew System::String(cs3));
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