这是程序:CIN是不是在等待输入
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main(){
string strKingdom = "";
bool conquered_me;//see if was conquered, was going to use this on other program and true = game over.
int gold;
int food;
int citizens;
int soldiers;
cout << endl <<"Name of kingdom: ";
cin >> strKingdom;
cout << endl << "were you conquered (true/false): ";
cin >> conquered_me;
cout << endl << "How many gold do you have?:";
cin>>gold;
cout << endl << "How many food do you have?:";
cin >> food;
cout << endl << "How many citizens do you have?:";
cin >> citizens;
cout << endl << "How many soldiers do you have?:";
cin >> soldiers;
return 0;
}
的问题是,当我编译它的编程'只让我插入的第2个变量,然后它显示的剩余的问题(编译后):
王国的名字:史蒂夫
是你征服(真/假):假
多少黄金,你有?: 多少FOO d你有吗?: 你有几个公民?: 你有几个士兵?:
你给的确切输入是什么?我猜测它正在读取您给出的“6”值的“2”输入。 (你有没有空间在你的王国的名字吗?看看:http://www.cplusplus.com/reference/string/string/getline/ –
只是不要使用'istream :: operator >>' 。为了获得用户输入,使用'std :: getline()'并解析结果字符串。 –
因此,存储std :: string是唯一可用的。下面的数据类型,包括那bool,导致你的失控行为,这是你的一个线索:-) – donjuedo