Results 1 to 2 of 2

Thread: take in a string

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Posts
    152

    Exclamation take in a string

    I have a function that prints a bunch of junk, then leaves it up to the user to determine what they want to do next. I want them to type in the string "run hello.exe" and then whenever they type in something other than that, I want the program to say "Bad command" and keep doing that until the user types the correct string. How should I go about this?

    --Thanks

  2. #2
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Code:
    #include <string>
    #include <iostream>
    using namespace std;
    
    //...
    
    string input;
    
    getline(cin, input);
    
    while (input != "run hello.exe")
    {
        cout << "Bad command" << endl;
        getline(cin, input);
    }
    Something like that should work.
    Alcohol & calculus don't mix.
    Never drink & derive.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width