【问题标题】:Getting a compilation error in VS2010 by following the first hello world example按照第一个 hello world 示例在 VS2010 中出现编译错误
【发布时间】:2011-05-13 08:28:32
【问题描述】:

我刚开始学习 MFC..在这里找到了一个教程 http://bit.ly/j2uhHO..刚刚在 VS2010 中尝试了同样的事情,但是在这段代码中出现了编译错误..

void CChildView::OnPaint() 
{

    CPaintDC dc(this); // device context for painting

    dc.TextOut(0, 0, "Hello, world!");

    // TODO: Add your message handler code here

    // Do not call CWnd::OnPaint() for painting messages
}

错误是:

error C2664: 'BOOL CDC::TextOutW(int,int,const CString &)' : cannot convert parameter 3 from 'const char [14]' to 'const CString &'

任何人都可以解决这个问题并建议一些 mfc 教程..谢谢你..

【问题讨论】:

    标签: c++ visual-studio-2010 mfc compiler-errors visual-c++-2010


    【解决方案1】:

    错误告诉你到底哪里错了。

    error C2664: 'BOOL CDC::TextOutW(int,int,const CString &)' : cannot convert parameter 3 from 'const char [14]' to 'const CString &'
    

    TextOutW() 期望 const CString & 作为第三个参数,而您传递的是 const char [14]

    你需要做的:

    dc.TextOut(0, 0, L"Hello, world!");  
    

    它以函数所需的格式传递第三个参数。

    要参考 MFC 资源,请参阅 this

    【讨论】:

    • 非常感谢..你能给我推荐一些适合初学者的 MFC 教程
    【解决方案2】:

    问题是 Windows 默认使用宽字符 wchar_t 来表示文本。你需要

        dc.TextOut(0, 0, L"Hello, world!"); 
    

    【讨论】:

      猜你喜欢
      • 2015-08-30
      • 1970-01-01
      • 1970-01-01
      • 2011-07-12
      • 1970-01-01
      • 2012-10-22
      • 2017-11-06
      • 2022-07-13
      • 1970-01-01
      相关资源
      最近更新 更多