VS2005的一个常见编译错误的解决方法

来源:互联网 发布:python与数据分析 编辑:程序博客网 时间:2024/05/17 03:00

 VS6.0里写个最简单的语句
MessageBox("Hello,World!");
编译运行没有任何错误。

而在VS2005写
MessageBox("Hello,World!");
出现错误提示:
error C2664: 'CWnd::MessageBoxW' : cannot convert parameter 1 from 'const char [13]' to 'LPCTSTR'

解决方法是:
MessageBox(_T("Hello,World!"));或MessageBox(TEXT("Hello,World!"));

原因:
2005中默认的是unicode的,char是非unicode的。不同于以前在6.0中的写法MessageBox("Hello,World!")。
也可以在VS2005项目属性中改变设置 General->Character Set->Not Set

 

  其他类似需要直接使用"Hello World"常量字符串的地方解决方法同上。

原创粉丝点击