I have written this program first to only include first and last name..how could I know include the middle name?
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
//initializing variables
string str;
int i, index;
//prompting user to input name
cout << "Enter a first middle and last name: " << endl;
//telling computer to read input
getline(cin, str);
//setting index to look at each character until space is found
index = str.find(' ');
//setting index for read the number of characters in last name once space
//was found
i = index + 1;
while(str[i])
{
//output last name
cout << str[i];
i++;
}
//setting a comma between last and first name
cout << ", ";
//setting index for reading the number of characters in first name
for(i = 0; i < index; i++)
//output first name
cout << str[i];
return 0;
}