gpt4 book ai didi

c++ - 我在使用 C++ 的刽子手游戏中遇到错误

转载 作者:行者123 更新时间:2023-11-28 01:40:01 26 4
gpt4 key购买 nike

我正在尝试为我正在做的一个小项目拼凑一个刽子手游戏,但我遇到了这些错误。我想知道是否有人可以指出正确的方向来引用这些错误。我已经指出了我在代码中收到的错误。我对编码比较陌生,如果这看起来微不足道,请原谅我

#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 是一个 keyword在 c++ 中,只能用于它保留的目的。为您的阵列命名。

来自 http://en.cppreference.com/w/cpp/language/identifiers :

An identifier can be used to name objects, references, functions, enumerators, types, class members, namespaces, templates, template specializations, parameter packs, goto labels, and other entities, with the following exceptions:

  • The identifiers that are keywords cannot be used for other purposes;
  • The identifiers with a double underscore anywhere are reserved;
  • The identifiers that begin with an underscore followed by an uppercase letter are reserved;
  • The identifiers that begin with an underscore are reserved in the global namespace.

关于c++ - 我在使用 C++ 的刽子手游戏中遇到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47581792/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com