int pos = name.find('t');
int pos2 = name.find('T');
if (pos == string::npos && pos2 == string::npos) {
cout << "There is no t in your name" << endl;
}
else if (pos > 0) {
cout << "t is in position " << pos << endl;
}
else {
cout << "T is in position " << pos2 << endl;
}
Is there a easier way, or more efficient way to find both a lowercase and upper case t? I'm new to programming, any help would be appreciated.
You could convert the string to lowercase first and then just search for lowercase letters. If you need to know the case of the original letter, just look at it in the same index in the original string.
As for converting a string to lowercase in C++, a quick Google search should give you the info you need - just be aware that it's a lot harder if you want to support other languages with UTF-8. In some languages, a letter in one case corresponds to two letters in the opposite case.