I used your code and just added some parsing around it. You really are very close.
I can't help myself. For user input, I always use getline() followed by a stringstream to parse the words from the line. I find it avoids a lot of edge cases that get me into quicksand.
When getline() gets an input, it returns true unless it has problems. If the user inputs Ctrl-d, it will return false. Ctrl-D is basically an EOF (end of file) code, which works well in this case (as long as you are not trying to input the Ctrl-d from inside your debugger. Mine does not like that.
Note that I am using std::string in place of an array. std::string can be treated like an array for subscripting, but it prints nicely and has other functions that make it better for processing character strings.
#include <iostream>
#include <string> // Allow you to use strings
#include <sstream>
int main(){
std::string input_line;
std::string fName;
std::string lName;
std::cout << "Please enter students as <lastname>, <firstname>\n"
"Press ctrl-D to exit\n";
while(std::getline(std::cin, input_line)){
std::istringstream ss(input_line);
ss >> lName;
// remove trailing comma. We could leave it in and all would work, but
// it just feels better to remove the comma and then add it back in
// on the output.
if(lName[lName.size() - 1] == ',')
lName = lName.substr(0, lName.size() - 1); // Substring without the comma
ss >> fName;
for (int x = 0; x < fName.length(); x++) // could start at x=1, but this works.
{
fName[x] = tolower(fName[x]); // make all chars lower case
}
fName[0] = toupper(fName[0]);
for (int x = 0; x < lName.length(); x++)
{
lName[x] = tolower(lName[x]);
}
lName[0] = toupper(lName[0]);
std::cout << "Student: " << lName << ", " << fName << std::endl;
}
}