I am creating a program in C++ that allows a user to input the number of times he or she wants to be prompted for three separate inputs, ie.
how many would you like: 2
enter here: 123.45/N 32.45/W Los Angeles
enter here: 22.22/N 223.4/E Hong Kong
The way I get the three separate inputs is by creating three string variables, and doing this:
cin << input1 << input2;
getline(cin, input3);
I have a parser in a separate file that I created that gets the number input out of the first two strings and does some calculations on it.
The problem I'm having is visualizing how to set up a system only using the std library, where I can have the user enter the number of times they want to input places, and then have the program create 3 unique strings I can reference later for calculations, and have it do cin/getline the amount of times the user enters.
One way I thought of was creating a function that takes an integer (the amount the user entered) and goes through a for loop which calls cin and getline. The problem with that is, how do I save and reference the values the user inputs for calculations later on? ie.
void inputAmount(int n) {
for(int i = 0; i < n; i++) {
cin << input1 << input2;
getline(cin, input3);
}
}
Where n is the amount of lines the user wants to enter. I tried to create an array of strings and initializing it with (n * 3) elements, but that apparently doesn't work with C++ since the variable must be constant and declared. I'm just confused on how to proceed, or how to achieve this.
std::vector?