错误C2065:CP':未声明的标识符 [英] error C2065: 'cp' : undeclared identifier

查看:984
本文介绍了错误C2065:CP':未声明的标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的C,我发现这个教程的字符串和数组在互联网上,并试图做方案。他们使用Eclipse和我使用Visual Studio 2010的...请帮助和解释。
我得到了这些问题:

 错误C2143:语法错误:缺少;前型
错误C2143:语法错误:缺少;前型
错误C2143:语法错误:在类型失踪)
错误C2143:语法错误:缺少;前型
错误C2065:CP':未声明的标识符
错误C2100:非法的间接
警告C4552:'=!:经营者有没有影响;预计运营商的副作用
错误C2059:语法错误:')'
错误C2065:CP':未声明的标识符
错误C2143:语法错误:缺少;前{
错误C2065:CP':未声明的标识符
错误C2100:非法的间接

这是code:

 的#include<&stdio.h中GT;
#包括LT&;&CONIO.H GT;
INT主(字符的argc,焦炭** argv的){
    个char [] =字符串;
    的printf(字符串是:%S \\ N,S);    对于(字符* CP = S;!* CP = 0; ++ CP){
        的printf(char是%C \\ n,* CP);
    }
    残培();
}


解决方案

微软的C编译器仅实现C90标准(加了一些扩展)。它不具有较新的C99或C11标准的全面支持。见(投票支持!)在MS连接这个bug报告鼓励他们增加对现代C.的由编译器团队这个博客条目还包含一些相关的信息。

其结果,虽然是你不能在循环初始化声明变量。事实上,你可以声明变量的唯一地方是在块的最顶端。

如果您移动 CP 的声明,该方法块的顶部,它会编译就好了。

  INT主(字符的argc,焦炭** argv的){
    个char [] =字符串;
    字符* CP = S; //移动到这里    的printf(字符串是:%S \\ N,S);    为(;!*厘泊= 0; ++ CP){
        的printf(char是%C \\ n,* CP);
    }
    残培();
    返回0; //你应该返回一定的价值
}

另外,你可以在你的函数体中引入一个新的块范围。

I am a new to C, I found this tutorial about string and arrays on the internet, and tried to do the program. They are using eclipse and I am using Visual Studio 2010...please help and explain. I am getting these problems:

error C2143: syntax error : missing ';' before 'type'
error C2143: syntax error : missing ';' before 'type'
error C2143: syntax error : missing ')' before 'type'
error C2143: syntax error : missing ';' before 'type'
error C2065: 'cp' : undeclared identifier
error C2100: illegal indirection
warning C4552: '!=' : operator has no effect; expected operator with side-effect
error C2059: syntax error : ')'
error C2065: 'cp' : undeclared identifier
error C2143: syntax error : missing ';' before '{'
error C2065: 'cp' : undeclared identifier
error C2100: illegal indirection

This is the code:

#include <stdio.h>
#include <conio.h>


int main(char argc, char**argv){
    char s[] = "string";
    printf("string is: %s\n", s);

    for(char *cp = s; *cp !=0; ++cp) {
        printf("char is %c\n", *cp);
    }
    getch();
}

解决方案

Microsoft's C compiler only implements the C90 standards (plus a few extensions). It does not have full support for the newer C99 or C11 standards. See (and vote for!) this bug report on MS Connect to encourage them to add support for modern C. This blog entry from the compiler team also contains some relevant information.

The upshot, though, is that you cannot declare variables in the initialization of a for loop. In fact, the only place you can declare variables is at the very top of a block.

If you move the declaration of cp to the top of the method block, it will compile just fine.

int main(char argc, char**argv){
    char s[] = "string";
    char *cp = s;//move to here

    printf("string is: %s\n", s);        

    for(; *cp !=0; ++cp) {
        printf("char is %c\n", *cp);
    }
    getch();
    return 0;// you should return some value
}

Alternatively, you can introduce a new block scope in the body of your function.

这篇关于错误C2065:CP':未声明的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆