Any way to pull the first letter of a string, and then determine, through science, whether or not its lower case so I can then apply C++ magics.
i know about the islower()
i tink it has to be a Char type. so i need to take my string and pull the first Char out of it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
string myName;
char c;
cout << "Enter name: " ;
getline(cin, myName);
// now somehow get variable c from string myName
// then check if c islower()
// then replace c with upper
?? then put back into string...aaaaargh
i need to take myName and search for it in a file, so i need to somehow put that newly upper cased letter back into the original string and then use that to perform the search.
#include <iostream>
#include <string>
#include <cctype>
int main()
{
std::string my_name ;
std::cout << "enter name: " ;
std::getline( std::cin, my_name ) ;
if( !my_name.empty() )
{
// if first letter of my_name is a lower case character, convert it to upper case
my_name.front() = std::toupper( my_name.front() ) ;
// note: you may ant to trim leading white space characters
// and adjust the case of other characters of the name. for instance:
// " gaBriel garCía márQuez" => "Gabriel García Márquez"
std::cout << my_name << '\n' ;
// search for name in a file
}
}