Validating concatenated cin inputs (C++)
Hi guys,
I am trying to do a simple, CLi ftp client/server c++ application. On the client end, once started, the command prompt will be: ftp>> just like a regular command line software. At one point, I am suppose to let use key in the following to transfer file: Quote:
I achieve that by issuing the following commands: Code:
cin >> a >> b; My question is, how can I validate the input, such that, if a user enters only 'put' or 'put fileFromClient' (basically not full commands which consist of the 3 arguements), I can capture it and prompt the user? Right now, by concatenating cin, the software will keep waiting, such that if I type 'put', hit the return key, the application will appear to be waiting (for the next 2 input). How can I capture the errornous user input from the moment the user hit the return key? and not let the program wait for the next 3 inputs from user, differentiate by the return key? I tried using cin.good() but i think I am not getting it right... anyone? thanks! ps: this is for a school assignment, but I'm just asking about how can I validate concatenated inputs... not asking help for my work hehe - in case you're wondering ;) |
You probably want to read the whole line, using the template method getine(), and then analyse the line for correctness.
|
you mean cin.getline()?
I tried.. but that way I can't ensure i get 3 inputs on one line, without having the user enter it 3 times separately |
well that's why I said you need to check the line that has been read; that would basically mean split it up into tokens, broken down by spaces and see if there are three.
|
so its not possible to prevent the user from pressing the 'return' key after keying in just 1 argument?
i was looking for possible ways to capture the user's action of entering, say: Code:
put fileFromClient *hit return* |
Quote:
|
All times are GMT -5. The time now is 09:24 PM. |