1> error C2664: 'sprintf' : cannot convert parameter 1 from 'const char [27]' to 'LPCTSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
error C2664: “sprintf”: 不能将参数 2 从“const char”转换为“LPCWSTR”与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
问题的原因是字符串ANSI和Unicode编码的区别: VC6与VS2003等默认使用ANSI编码,而VS2008默认采用Unicode。简单的说,ANSI用1个字节表示字符,Unicode用2个字节表示1个字符。
在VS2008中,设置如下:
1 进入project菜单进入最后一个***properties。
2、选择configuration properties --> General -->character set中设置 not set。
3、OK! 错误消失。
本文介绍了解决从Visual C++(VC)迁移到Visual Studio(VS)时出现的编译错误方法,特别是关于sprintf函数使用的转换问题。在VS2008中由于默认采用Unicode编码而非ANSI,导致了字符串类型不匹配的错误。文章提供了详细的步骤来更改字符集设置以消除此类错误。
9587

被折叠的 条评论
为什么被折叠?



