cannot convert from w_char_t * to const char * 编译tinyXml 工程出现的问题

cannot convert from w_char_t * to const char *

 

最近要使用TinyXML ,从codeproject上面下载了一个CTreeCtrlXML 工程文件,

直接编译没有问题,

后来移植到自己的工程中出现了如下问题:

cannot convert from w_char_t * to const char *

 

等一系列的字符转换的问题,

 

一开始强制转换后,能编译通过,但是仍旧不能成功运行

 

后来视图解决该问题

发现这篇文章:

http://blog.csdn.net/dadalan/archive/2009/03/04/3958116.aspx

 

Question

I'm trying to compile a piece of code such as:

MessageBox("Hello world!");

... when I compile the project, the compiler yields:

error C2664: 'CWnd::MessageBoxW' : cannot convert parameter 1 from 'const char [12]' to 'LPCTSTR'

What am I doing wrong?

Problem

This error message means that you are trying to pass a multi-byte string (const char [12]) to a function which expects a unicode string (LPCTSTR). The LPCTSTR type extends to const TCHAR*, where TCHAR is char when you compile for multi-byte and wchar_t for unicode. Since the compiler doesn't accept the char array, we can safely assume that the actual type of TCHAR, in this compilation, is wchar_t.

Resolution

You will have to do one of two things:

Change your project configuration to use multibyte strings. Press ALT+F7 to open the properties, and navigate to Configuration Properties > General. Switch Character Set to "Use Multi-Byte Character Set".
Indicate that the string literal, in this case "Hello world!" is of a specific encoding. This can be done through either prefixing it with L, such as L"Hello world!", or surrounding it with the generic _T("Hello world!") macro. The latter will expand to the L prefix if you are compiling for unicode (see #1), and nothing (indicating multi-byte) otherwise.
Variations

Another error message, indicating the same problem, would be:

cannot convert parameter 1 from 'const char [12]' to 'LPCWSTR'

Where LPCWSTR maps to a wchar_t pointer, regardless of your build configuration. This problem can be resolved primarily by using solution #2, but in some cases also #1. A lot of the Microsoft provided libraries, such as the Platform SDK, have got two variations of each function which takes strings as parameters. In case of a unicode build, the actual functions are postfixed W, such as the MessageBoxW seen above. In case of multi-byte, the function would be MessageBoxA (ASCII). Which of these functions is actually used when you compile your application, depends on the setting described in resolution #1 above.

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/dadalan/archive/2009/03/04/3958116.aspx

 

 

简单的说就是改字符编码

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值