我一直试图测试我发现的这个旧的“文字冒险”的东西,
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
/////////////////////////////////////////////////////// VARIABLES //////////////////////////////////////////////////////////
string name;
string shipName;
int health;
int crewCount;
int armyTotal, activeArmy;
int casualtiesCount, woundedCount, healedCount;
// 'food' as in a whole meal (beverage, chewables, etc)
int foodCount;
////////////////////////////////////////////////////// INTRODUCTIONS ///////////////////////////////////////////////////////
cout << "What is thy name?\nName: ";
cin >> name;
cout << endl << "What will you name your ship?\nShip Name: ";
cin >> shipName;
cout << "\nSETTING: You are floating through space on giant space cruiser " << endl << "known as the " << shipName << ".\n You are on a random patrol sorti, just looking out for any trouble...";
cout << "Press ENTER to continue...";
cin.get();
cout << "\nFrom here on out, type corresponding number to which choice you want to make.\nPress ENTER to continue...";
cin.get();
//////////////////////////////////////////////////////// BEGINNING ////////////////////////////////////////////////////////
cout << endl << "Admiral " << name << ", we need you on flight deck.";
cout << "1: Go to flight deck.";
cout << "2: Go to kitchen.";
cout << "3: Go to MedBay.";
cout << "4: Do nothing.";
}
我收到错误:
cin >> name;
其中“&gt;&gt;”不匹配任何操作数。 我清楚地记得这段代码在某些时候我确实相信。如果我尝试跳过,我会收到一个错误,它找不到exe(并且没有选项来构建最终版)
很抱歉不清楚,但我几年没有使用过C ++,几乎所有东西都很生疏。什么样的智慧可以摆脱?
答案 0 :(得分:2)
您需要#include <string>
。这就是定义实际运算符的地方。有可能在过去,<iostream>
可能已包含它,但允许但不需要(或保证)。