Reputation: 964
I'm making a command-line word editor program. The user is prompted to input a control character to make a change to the file. I'm having trouble with command 'D' which deletes either a single line of text, or a range of text.
input D:
D 3 --deletes line 3
D 2 8 --deletes lines 2 to 8 inclusively
How do you make it so that the second line is optional? I have cin << char << int << int, but I can't find a way to make that optional.
Upvotes: 3
Views: 572
Reputation: 98368
Do
std::string line;
std::getline(std::cin,line);
and then analyze the line manually, first splitting it into words.
It could be useful to have a function:
void ToWords(const std::string &line, std::vector<std::string> &words);
But the implementation is left as an exercise to the reader ;-).
Upvotes: 5