0

Here's what I have please tell me if I have to post everything. What I want is if they type " tcc fcc (enter)" I want cube.rotateTopNeg90() then cube.rotateFrontNeg90() to work on the cube thats printed. edit: Sorry, that's my question above, right now the commands only work one at a time (ie: 'tcc' (enter) 'fcc' (enter) ...) I want to it to be something like this ( 'tcc' 'fcc' 'tcc' 'tcc'....(repeat as many times as they like) (enter)) then each are processed consecutively. That's why I can't just use cin. I've asked this before here but I really don't know how to do it exactly.

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;
}
2
  • 2
    I think using cin << s; instead of getline(...) would do everything you want Commented Feb 25, 2013 at 13:30
  • 1
    And the 1 million euro (lets go cheap) question is? Commented Feb 25, 2013 at 13:30

1 Answer 1

0

I think the following would solve your problem; std::getline is taking in a whole line from std::cin which is more than you want as your operations work on a per token basis. std::cin tokenises on whitespace so op>> is better suited to your application.

const std::string rotateTopNeg90   ="tcc",
                  rotateFrontNeg90 ="fcc";

while(std::cin >> s) {
   if (s == rotateTopNeg90 )
        cube.rotateTopNeg90();
   else if ( s == rotateFrontNeg90 )
       cube.rotateFrontNeg90();
   cube.display();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.