0

我一直在尝试构建我发现的这个旧的“文本冒险”,

#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; 

其中“>>”不匹配任何操作数。我清楚地记得这段代码在我相信的某个时候有效。如果我尝试向前跳过,我会收到一个找不到 exe 的错误(并且没有 Build Final 选项)

抱歉不清楚,但我已经有几年没有使用 C++ 了,几乎所有东西都生锈了。有什么智慧可以流露出来吗?

4

1 回答 1

2

你需要#include <string>。这就是定义实际操作符的地方。有可能在过去,<iostream>可能已经包含它,它被允许但不是必需(或保证)。

于 2013-09-26T00:26:38.073 回答