简体   繁体   English

按照第一个hello world示例获取VS2010中的编译错误

[英]Getting a compilation error in VS2010 by following the first hello world example

i just started learning MFC..found a tutorial here http://bit.ly/j2uhHO ..just tried the same thing in VS2010 but getting a compilation error in this code.. 我刚刚开始学习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
}

And the error is: 错误是:

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

Can anyone solve this and suggest some mfc tutorials please..thank u.. 任何人都可以解决这个问题,并建议一些mfc教程。谢谢你...

The error tells you whats exactly wrong. 错误告诉你什么是完全错误的。

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

TextOutW() is expecting const CString & as the third parameter and you are passing const char [14] TextOutW()期望const CString &作为第三个参数,你传递const char [14]

You need to do: 你需要这样做:

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

Which passes the third argument in the format desired by the function. 它以函数所需的格式传递第三个参数。

For MFC resources to refer, you see this . 对于要引用的MFC资源,您会看到这一点

The problem is that Windows by default uses wide characters wchar_t for texts. 问题是Windows默认使用宽字符wchar_t作为文本。 You would need 你需要

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM