Hi,
I'm new to programming and currently reading for a degree in Computer Science.
I'm trying to figure out how to write a function that would read a string, take the first character in the string and change it to uppercase while changing the remaining letters to lowercase.
Such is that if one were to enter "john doe" or "jOHN "dOe" etc the function would read this in and change it to "John Doe"
#include <iostream>
#include <cctype>
usingnamespace std;
int main()
{
string str("jOHn dOE hyMeN");
str[0] = toupper(str[0]); //convert first character to upper case
for(size_t i = 1; i < str.size(); i++)
{
if(str[i] == ' ') //if character is space...
{
str[i+1] = toupper(str[i+1]); //convert the next after it to upper case
i++;
}
else
str[i] = tolower(str[i]);
}
cout<<str<<endl;
}