原文:http://blog.csdn.net/w343051232/article/details/7074788
由于cpp编译下列代码报错
- #include <cstdio>
- #include <cstring>
- int main()
- {
- wchar_t wstr[] = L"Hello!";
- int wlen = strlen(wstr);
- wprintf(L"%ls",wstr);
- int len;
- return 0;
- }
error C2664: 'strlen' : cannot convert parameter 1 from 'unsigned short [7]' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
于是将后缀名改成.c
却出现另外一个诡异的编译错误:error C2143: syntax error : missing ';' before 'type' 并且指向 int len;这行
将代码做如下修改却诡异般的编译过了
- #include <cstdio>
- #include <cstring>
- int main()
- {
- wchar_t wstr[] = L"Hello!";
- int len;
- int wlen = strlen(wstr);
- wprintf(L"%ls",wstr);
- return 0;
- }
不知道什么原因!!找了找资料。。。。原来It is a rule! 在纯C中,在一个代码块中变量声明必须在最前面
相关热门文章
给主人留下些什么吧!~~
评论热议