重複の可能性:
ISO C ++は、ポインターと整数の比較を禁止しています[-fpermissive] | [c ++]
#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それを解決するのに役立つものは何もないようです。""
代わりに使用''
し、に変更して正常に動作するため、人々はそれを機能させるようです''
。しかし、私はいつも使用してい''
ます!