im trying to get this code to work
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
string studentNames[5];
cout << "enter 5 student name: ";
for (int i = 0; i < 5; i++)
{
cin >> studentNames[i];
}
for (int i =0; i < 5; i++)
{
cout << studentNames[i] << " ";
}
cout << endl;
system("pause");
return 0;
}
|