Optional C ++ user argument
I am creating a program for an IL editor. The user is prompted for a control character to make changes to the file. I am having problems with the "D" command 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 do it so that the second line is optional? I have cin <char <int <int, but I can't find a way to make this optional.
+3
source to share
1 answer
Do
std::string line;
std::getline(std::cin,line);
and then parse the string manually by first splitting it into words.
It might be helpful to have a function:
void ToWords(const std::string &line, std::vector<std::string> &words);
But implementation is left as an exercise for the reader; -).
+5
source to share