Jay Kim
Jay Kim

Reputation: 843

how to handle input redirection

I have a simple menu, something like the following:

while(cmd != quit){
    cin >> cmd;
    swith(cmd){
        case 'a':
            blah();
            break;
        case 'b':
            boo();
            break;
     }
}

what would i have to do inorder to make sure it handles not only input from the console, but also file redirection in unix/linux?

thanks!

Upvotes: 1

Views: 189

Answers (2)

Xander
Xander

Reputation: 1715

There is fflush series of functions in C and C++. Think this can be of use when there is some issue with the streams.

Upvotes: 0

hc_
hc_

Reputation: 2628

Do you mean redirection as in:

echo 'a' | ./your_program

In that case you don't have to do anything special. The shell already directs your input into stdin of your program.

Upvotes: 5

Related Questions