0
以下是我必须告诉我是否必须发布所有内容的信息。我想要的是,如果他们键入“tcc fcc(enter)”我想cube.rotateTopNeg90()然后cube.rotateFrontNeg90()在打印的立方体上工作。 编辑:对不起,这是我的问题上面,现在的命令只有一次工作(即:'tcc'(enter)'fcc'(enter)...)我想它是这样的东西(' tcc''fcc''tcc''tcc'....(按照他们喜欢的次数重复)(输入)),然后每个连续处理。这就是为什么我不能只使用cin。我在here之前询问过这个问题,但我真的不知道如何去做。在C++中的一个输入中读取多个命令
class RubiksCube
{
public:
RubiksCube::RubiksCube() { /*stuff here*/ }
void display() { /*prints the cube unfolded here*/ }
void rotateTopNeg90() { /*moves top of the cube counterclockwise*/ }
void RubiksCube::rotateFrontNeg90() { /*moves front counterclockwise*/ }
}
//main
int main(int argc, char *argv[])
{
RubiksCube cube;
string s;
srand(time(0));
while (1)
{
string rotateTopNeg90 = "tcc";
string rotateFrontNeg90 = "fcc";
cube.display();
cout << "COMMAND:";
getline(cin,s);
istringstream stream(s);
if (s == rotateTopNeg90)
cube.rotateTopNeg90();
if (s == rotateFrontNeg90)
cube.rotateFrontNeg90();
}
return 0;
}
我认为使用'CIN << S;',而不是'函数getline(...)'会做你想要 – kassak 2013-02-25 13:30:15
而百万欧元一切(让我们去便宜)的问题是什么? – 2013-02-25 13:30:17