what i need to do is to ask the user to input a persons first name and last name and store it into stringName[i];
so stringName[i]; should contain one name(first and last)
Assume that the names will be separated with a space. so first1 last1 first 2 last2
i can get it to work with getline(cin, stringName[i]);
but i need it to be like: fisrt1 last1 = stringNames[0], first2 last2 = stringNames[1]
here is the original question:
Given an array declared as
string studentNames[5];
write the C++ code to populate the array from the keyboard with the first and
last name of students. Assume that the names will be separated with a space. Include prompts for input in your code. Mention any additional header files that you need besides string for your code.
Use getline function instead of cin, so you can do it first last, otherwise if you use cin, even if you type first last, it would only take first.
So: getline(cin,studentName[i]);
That would be very complicated..You would have to make it so after ever second space ( hoping the user doesn't accidently hit it twice ) that it puts the next two words into a different position in the array. You are best off with using getline. Otherwise use getline and get the whole line then seperate the string into multiple strings and put those into an array.