問題描述
可能的重復:
為什么我的簡單 C++ GUI應用程序顯示中文消息框?
我已經在 Visual C++ 中實現了如下代碼塊:
I have implemented this block of code as below in Visual C++:
int nResult=MessageBox(NULL,
(LPCWSTR)"An example of Cancel,Retry,Continue",
(LPCWSTR)"Message Box!",
MB_ICONWARNING|MB_ABORTRETRYIGNORE);
然而,無論我嘗試什么,它總是顯示一個中文消息框!因此,我只想為我的問題尋求任何解決方案以及為什么這里有中文信息.謝謝!
however, no matter what i tried, it always show a message box in chinese! Therefore, i just want to ask for any solution for my problem and why there is chinese message here. Thanks you!
推薦答案
您忘記在字符串字面量之前放置 'L'.修改如下:
You forgot to place 'L' before the string literal. Modify as follows:
int nResult=MessageBox(NULL,
L"An example of Cancel,Retry,Continue",
L"Message Box!",
MB_ICONWARNING|MB_ABORTRETRYIGNORE);
在 C++ 中,Unicode 字符串文字以 L
為前綴.如果您不添加前綴,則轉換為unicode string constant"將無濟于事,并會導致對內存位置的錯誤解釋.
In C++ unicode string literals are prefixed with L
. If you don't put the prefix, casting to 'unicode string constant' won't help and causes incorrect interpreting of the memory location.
這篇關于為什么C++中的消息框顯示中文消息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!