错误argument of type "char *" is incompatible with parameter of type "LPCWSTR"的解决方法
2011-10-14 10:41
645 查看
方法一:
方法一只针对新手,在vs2010中修改编码格式:
右键工程——》
选择“Properties”——》
选择“Configuration Properties”——》
再选择“General”——》
最后把“Project Default”下的“Character Set”修改为“Use Multi-Byte Character Set”(默认为“Use Unicode Character Set”)
这样对新手来说,就省了很多类型显示转换的工夫。但是这对学习windows不好,因为这样无法理解windows编程的特性、字符格式的原理。有精力还是不要用方法一,多折腾下就好了,请看方法二和三,会学到很多东西的。学习编程都是这样,不要贪图闲逸,一定要不畏苦难,遇到困难要想方设法搞懂:
1.为什么会出现这种错误?
2.出现这种错误的解决方法?
3.哪种方法最好,为什么?
4.联想自己遇到过的类似问题,比较、思考、总结。
相信你这样子会走得更远。
方法二:
方法二要引入 #include<tchar.h>,才能使用TEXT等进行转换
LPCWSTR str1 = TEXT("Hello");
LPCWSTR str2 = L"Hello";
LPCWSTR str3 = _T("Hello");
方法三:
这种是针对使用变量来存储字符串的解决方法。
const char* ch = "Hello";
WCHAR wCh[6];
MultiByteToWideChar( 0,0, ch, 5, wCh, 6); // MultiByteToWideChar函数用法请看MSDN
LPCWSTR str4 = wCh;
方法一只针对新手,在vs2010中修改编码格式:
右键工程——》
选择“Properties”——》
选择“Configuration Properties”——》
再选择“General”——》
最后把“Project Default”下的“Character Set”修改为“Use Multi-Byte Character Set”(默认为“Use Unicode Character Set”)
这样对新手来说,就省了很多类型显示转换的工夫。但是这对学习windows不好,因为这样无法理解windows编程的特性、字符格式的原理。有精力还是不要用方法一,多折腾下就好了,请看方法二和三,会学到很多东西的。学习编程都是这样,不要贪图闲逸,一定要不畏苦难,遇到困难要想方设法搞懂:
1.为什么会出现这种错误?
2.出现这种错误的解决方法?
3.哪种方法最好,为什么?
4.联想自己遇到过的类似问题,比较、思考、总结。
相信你这样子会走得更远。
方法二:
方法二要引入 #include<tchar.h>,才能使用TEXT等进行转换
LPCWSTR str1 = TEXT("Hello");
LPCWSTR str2 = L"Hello";
LPCWSTR str3 = _T("Hello");
方法三:
这种是针对使用变量来存储字符串的解决方法。
const char* ch = "Hello";
WCHAR wCh[6];
MultiByteToWideChar( 0,0, ch, 5, wCh, 6); // MultiByteToWideChar函数用法请看MSDN
LPCWSTR str4 = wCh;
相关文章推荐
- 错误argument of type "char *" is incompatible with parameter of type "LPCWSTR"的解决方法
- 错误argument of type "char *" is incompatible with parameter of type "LPCWSTR"的解决方法
- 错误argument of type "char *" is incompatible with parameter of type "LPCWSTR"的解决方法
- 错误:argument of type "char *" is incompatible with parameter of type "LPCWSTR"
- "const wchar_t is incompatible with parameter of type "LPCSTR"
- 关于Android Studio "This version of android studio is incompatible with the gradle version used."的解决方法
- parameter "bandwidth_type" is not a formal parameter of instantiated module的解决方法
- 不能将 "const char *" 类型的值分配到 "LPCWSTR" 类型的实体 错误解决方法
- 不能将"constchar*"类型的值分配到"LPCWSTR"类型的实体错误解决方法
- 1 IntelliSense: 不能将 "const char *" 类型的值分配到 "LPCWSTR" 类型的实体 错误解决方法
- The return type is incompatible with JspSourceDependent.getDependants():JasperException问题分析与解决方法
- angular Argument of type '"price"' is not assignable to parameter of type 'string[]'
- Android RecyclerView的案例讲述和"The hierarchy of the type ViewHolder is inconsistent"错误解决
- java中"no enclosing instance of type * is accessible"的解决方法
- linux下出现architecture of input file `*.o' is incompatible with i386:x86-64 output的解决方法
- mvn install Geoserver under ubuntu10.04 时遇到的错误:the API of the mojo scanner is not compatible with this plugin version. 的解决方法
- 不能将 "const char *" 类型的值分配到 "LPCWSTR" 类型的实体 错误解决方法
- caffe cudnn出现错误: declaration is incompatible with "const char *cudnnGetErrorString(cudnnStatus_t)"
- 不能将 "const char *" 类型的值分配到 "LPCWSTR" 类型的实体 错误解决方法
- JAVA编译错误 “No enclosing instance of type XXX is accessible”的解决方法