Upper/lower case

How can I make only my first letter upper case and all of the other letters lower case for the first, middle and last name. This program is a name formalize program, for an example if you wrote Mary Average User it would output User, Mary A. I want to be able to use it under #include <cctype> and it would be something like toupper and tolower with char. Please help me. Thanks


#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main()

{
string name;
cout << "Enter your name: ";
getline(cin,name,'\n');

string first, last, middle, output;

string::size_type firstSpace = name.find(' ', 0);

first = name.substr(0, firstSpace);

string::size_type secondSpace = name.find(' ', firstSpace+1);

if(secondSpace == string::npos)
{

last = name.substr(firstSpace+1);

output = last + ", " + first ;
}
else
{

middle = name.substr(firstSpace+1, secondSpace-firstSpace-1);

last = name.substr(secondSpace+1);

output = last + ", " + first + " " + middle.at(0) + ".";
}

cout<< output <<endl ;
return 0;
}
closed account (E0p9LyTq)
Duplicate post:

http://www.cplusplus.com/forum/beginner/247114/
Topic archived. No new replies allowed.