So how can I do it?
the input should be like this:
david | 12.2 23.4 324.5 |
Jack |12.3 23.4 22.3 54.3 |
I don't know how many will the user enter names or data?
I should use an escape word like EXIT so when user types exit it goes to another function?
If I use cin.getline it skips to next line making the format this
| 12.23 34.3 344.3 |
it all should be in one line
Looks like English isn't your native language. Unforturnately, that means it is difficult for me to understand what you are trying to do.
getline() will accept input from the keyboard (or other source) and store it in a string variable. It has nothing to do with how the value of the variable is displayed on the screen or how it is stored in file or how it is printed on paper.
using namespace std;
cout << "enter the following string. DON'T push the ENTER key until the entire string is entered: david | 12.2 23.4 324.5 |";
cout << "enter the following string. DON'T push the ENTER key until the entire string is entered: Jack |12.3 23.4 22.3 54.3 |";
cout << firstInput;
cout << '\n'; //comment out this line to put both inputs on the same line
cout << secondInput;
Use a list or a vector or some other self expanding container to hold all the inputs. Use a loop to get the input. I'd still use string to hold each input.
bool getMoreInput = true;
//tell user how to enter input here
//get input here
//add input to inputs here
//ask user if they want to enter another input
//if answer is 'n' then change value of getMoreInput here