Simple C++ code (what's wrong here?)
- by JW
Noob to C++.
I'm trying to get user input (Last Name, First Name Middle Name), change part of it (Middle Name to Middle Initial) and then rearrange it (First Middle Initial Last).
Where am I messing up in my code?
--Thanks for ANY help you can offer!
...
#include <iostream>
using std::cout;
using std::cin;
#include <string>
using std::string;
int main()
{
string myString, last, first, middle;
cout << "Enter your name: Last, First Middle";
cin >> last >> first >> middle;
char comma, space1, space2;
comma = myString.find_first_of(',');
space1 = myString.find_first_of(' ');
space2 = myString.find_last_of(' ');
last = myString.substr (0, comma); // user input last name
first = myString.substr (space1+1, -1); // user input first name
middle = myString.substr (space2+1, -1); // user input middle name
middle.insert (0, space2+1); // inserts middle initial in front of middle name
middle.erase (1, -1); // deletes full middle name, leaving only middle initial
myString = first + ' ' + middle + ' ' + last; //
return 0;
}