First, my program works.
I'm posting my code for my own personal benefit with the help of your guidance to know of any better way of handling this code. I was considering the use of
while(cin >> grabname)
to possibly continue grabbing from the input stream until '\n' was reached (hoping <enter> would made an eof approach). Seeing how this made an infinite loop, I had then chosen to switch from strings to char then back to strings. It appeared this was the only solution that I could come up with that allowed a check for any additional values of non-whitespace or '\n'. This approach doesn't seem very smooth to me, any recommendations with string manipulations?
I know I could try getline(cin, FullName), then split it them all through a function with vector<string> but the text did not recommend this and suggesting 3 string variables, mentioned it would be easier that way.
The point of the program is to output a persons name LastName, FirstName MiddleInitial. If no middle name or initial was given then output would look as follows, LastName, FirstName.
Just as a refresh statement for any that did not know -this is not for any class.-
Home-study 100%.
If this is an inappropriate post please let me know.
Thanks in advance.
int main(){
char aChar;
string FirstName, MiddleName, LastName;
cout << "What is your first and last and possibly middle name?\n";
cin >> FirstName >> LastName;
cin.get(aChar);
while(aChar != '\n' && aChar == ' ')
cin.get(aChar);
if(aChar != '\n' && aChar != ' ') {
string temp;
cin >> temp;
MiddleName = LastName;
LastName = aChar + temp;
}
output(FirstName, MiddleName, LastName);
return 0;
}