【发布时间】:2013-01-17 09:28:44
【问题描述】:
根据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
CString::Format 的微软文档说:
...当您将字符串作为可选参数传递时,您必须将其显式转换为 LPCTSTR...
我总是使用“错误”的方式(没有 LPCSTR 演员),我从来没有遇到过问题。
我在这里错过了什么吗?
【问题讨论】: