Does anybody know why this codes is not correct according to this site:
CString First( "John" );
CString Last( "Doe" );
CString Name;
Name.Format( "%s %s", First, Last ); // Name may be garbage text
Name.Format( "%s %s", (LPCSTR)First, (LPCSTR)Last ); // this is the correct way
The Microsoft documentation of CString::Format says:
...When you pass a character string as an optional argument, you must cast it explicitly as LPCTSTR...
I always use the "wrong" way (without the LPCSTR cast) and I never had problems.
Am I missing something here ?