我正在尝试将一个挂钩游戏组合在一起,以进行我正在做的小项目,但我会遇到这些错误。我想知道是否有人可以将我指向正确的方向来引用这些错误。我指出了我在代码中收到的错误。我对编码是相对较新的,所以请原谅我,如果这似乎微不足道
#include<iostream>
#include<string>
int main()
{
int t=1;
while(t>0)
{
char c;
char a[]="hello";
int wrong=0;
std::cout<<"guess the word";
char new[5]={0};<----------------error: Expected unqualified-id
int no;
char letter;
for(int i=0;i<a.length;i++)<---------error: Member reference base type 'char [6]' is not a structure or union
{
std::cout<<"x";
}
while(wrong<7 && strcmp(new,a)!=0)<---------error: Expected a type
{
no=0;
std::cin>>letter;
for(int i=0;i<5;i++)
{
if(new[i]==letter)<----------------error: Expected a type
{
no=1;
std::cout<<"yes"<<std::endl;
}
}
if(no<1)
{
std::cout<<"no"<<std::endl;
wrong++;
if(wrong==1)
{
std::cout<<" O"<<std::endl;
}
if(wrong==2)
{
std::cout<<" O"<<std::endl;
std::cout<<"/"<<std::endl;
}
if(wrong==3)
{
std::cout<<" O"<<std::endl;
std::cout<<"/|"<<std::endl;
}
if(wrong==4)
{
std::cout<<" O"<<std::endl;
std::cout<<"/|\"<<std::endl;
}
if(wrong==5)
{
std::cout<<" O"<<std::endl;
std::cout<<"/|\"<<std::endl;
std::cout<<" |"<<std::endl;
}
if(wrong==6)
{
std::cout<<" O"<<std::endl;
std::cout<<"/|\"<<std::endl;
std::cout<<" |"<<std::endl;
std::cout<<"/"<<std::endl;
}
if(wrong==7)
{
std::cout<<" O"<<std::endl;
std::cout<<"/|\"<<std::endl;
std::cout<<" |"<<std::endl;
std::cout<<"/ \"<<std::endl;
}
}
}
if(wrong==7)
{
std::cout<<"play again"<<std::endl;
std::cin>>c;
}
else
{
std::cout<<"Congratulations!!!"<<std::endl;
std::cout<<"play again"<<std::endl;
std::cin>>c;
}
if(c=='y')
{
t=1;
}
else
{
t=0;
}
}
return 0;
}
char new[5]={0};
正在尝试创建一个名为 new
的数组。但是,new
是C 中的关键字,只能用于保留的目的。命名您的数组。
来自http://en.cppreference.com/w/cpp/language/Identifiers:
标识符可用于命名对象,引用,功能,枚举者,类型,类成员,名称空间,模板,模板专业,参数包,goto标签和其他实体,但以下例外:
>
- 是关键字的标识符不能用于其他目的;
- 保留具有双重下划线的标识符;
- 以下划线开始的标识符,然后是大写字母;
- 以下划线开头的标识符保留在全局名称空间中。