本文介绍了在VS 2005中将String *转换为wchar_t的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 您好我正在使用VS 2005来升级演示项目,我在一堆代码中遇到了这个错误 ,这些代码在VC ++ 2003上编译得很好。 < code> wchar_t __pin * pVal = PtrToStringChars(val); < / code> < ;错误> 错误1错误C2440:''初始化'':无法将''__ const_Char_ptr'' 转换为''wchar_t __pin *'' < / error> 任何人都可以给我一个如何解决这个问题的提示。还包括vcclr.h。 谢谢, blair 解决方案 我_think_新语法要求目标是const const_cast< interior_ptr<字符> >(PtrToStringChars(val)); 我应该告诉你,我还没有与VS2005进行任何互操作和 避风港'编译这个。 对旧的差异的一个很好的介绍MC ++语法和 " new" C ++ / CLI语法在这里: http://msdn.microsoft.com/library/de...TransGuide.asp 问候, 将 用于固定的C ++ / CLI语法是 cli :: pin_ptr< wchar_t> pVal(PtrToStringChars(val)); 我还没试过这个例子。 或者你使用旧的MC ++句法?我从未在VC ++ 2005中使用它。 Tom 用于固定的C ++ / CLI语法是 CLI :: pin_ptr< wchar_t的> pVal(PtrToStringChars(val)); 我还没试过这个例子。 或者您使用旧的MC ++语法?我从未在VC ++ 2005中使用它。 Tom Hi I am using VS 2005 to upgrade a demo project and I came across this errorin a bunch of code which compiles fine on VC++ 2003.<code>wchar_t __pin* pVal = PtrToStringChars( val );</code><error>Error1error C2440: ''initializing'' : cannot convert from ''__const_Char_ptr''to ''wchar_t __pin *''</error>Can anyone give me a hint on how to fix this. Also vcclr.h is included.Thanks,blair 解决方案I _think_ that the new syntax requires that the target be constconst_cast< interior_ptr<Char> >( PtrToStringChars(val) );I should tell you, though, that I haven''t done any interop with VS2005 andhaven''t compiled this.A good introduction to the differences with the "old" MC++ syntax and the"new" C++/CLI syntax is here: http://msdn.microsoft.com/library/de...TransGuide.aspRegards,WillThe C++/CLI syntax for pinning iscli::pin_ptr<wchar_t> pVal(PtrToStringChars(val));I haven''t tried this example, though.Or are you using the old MC++ syntax? I''ve never used that with VC++ 2005.Tom The C++/CLI syntax for pinning is cli::pin_ptr<wchar_t> pVal(PtrToStringChars(val)); I haven''t tried this example, though. Or are you using the old MC++ syntax? I''ve never used that with VC++ 2005. Tom 这篇关于在VS 2005中将String *转换为wchar_t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-22 22:03