现在的位置: 首页 > 综合 > 正文

error C2143: syntax error : missing ‘;’ before ‘type’

2013年12月03日 ⁄ 综合 ⁄ 共 591字 ⁄ 字号 评论关闭

由于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中,在一个代码块中变量声明必须在最前面

抱歉!评论已关闭.