In a program i'm writing i'm supposed to read user input on one line and the user will have a max of 6 things on the line. I've been trying to figure out how to read in this unknown number of things. Ideally I want all of these stored in an array. I tried using cin and using an array like this: cin >>array[0]>>array[1]>>array[2]>>array[3]>>array[4]>>array[5];
This however will not allow them to skip any of the array. I have the rest of the program written but this is the last part I need.
Examples of user usage:
1. Enter command and all arguments: wc
2. Enter command and all arguments: wc -l
3. Enter command and all arguments: grep -i file.*
etc...
I would take the full line written by the user with std::getline(std::cin,stdstringnamewheretosave);
Then, adapt this from stack overflow to divide your std::string into parts, this will loop with each word written delimited by a space, you can break the loop after 6 words have been processed: