#include <iostream>
using namespace std;
int main()
{
char name[20];
char color[20];
char response[20];
int age;
cout << "What is your name?\n";
cin.getline(name, 20); cout << endl;
cout << "What is your favorite color?\n";
cin.getline(color, 20); cout << endl;
cout << "How old are you?\n";
cin >> age;
cout << "Your name is " << name << ", your favorite color is " << color << " and you are " << age << " years old!\n";
cin.get();
cout << "You wake up from bed all you know is your name and age.\n";
cout << "You are wearing a plain " << color << " t-shirt.\n";
cout << "You see a gun on the table.\n";
cout << "You see a door.\n";
cout << "What do you do?\n";
cin.getline(response, 20);
if(response == 'Pick up the gun')
{
cout << "You pick up the gun.\n";
cout << "Knock down the door with it? (Y/N)\n";
cin.getline(response, 20);
if(response == 'Y')
{
cout << "The door opens.\n";
cout << "You see a zombie.\n";
cout << "You see an open window.\n";
cout << "What do you do?\n";
cin.getline(response, 20);
if(response == 'Shoot the zombie')
{
cout << "The zombie dies and it attracts other zombies.\n";
cout << "GAME OVER!\n";
cin.get();
return 0;
}
else if(response == 'Jump out the window')
{
cout << "The zombie does not hear you and you safely make it out!\n";
cout << "VICTORY!\n";
cin.get();
return 0;
}
}
else if(response == 'N')
{
}
}
else if(response == 'Open the door')
{
cout << "It appears to be locked.\n";
}
return 0;
}
试图制作一个超级超短和简单的文字 rping 游戏,但它不起作用!我的错误是:
24 error:no matching function for call to 'std::basic_istream<char>::getline(std::string&)'
并且在每一行都有if
我得到的响应内容 C++ 禁止指针和整数之间的比较
我没有试图以任何形式或形式 o_o 这样做似乎无助于解决它。人们似乎让它工作,因为他们使用""
而不是,''
他们改变它''
,它工作正常。但我一直在使用''
!