so for my assignment I have to write a program. One of the function requires us to compare a char to a list of strings to see how many words are in that list that start with that char and then add it to another string.
My question is how do I compare the two? A char to the first letter in the string in the list
My question is how do I compare the two? A char to the first letter in the string in the list
1 2 3 4 5 6 7 8
char c = 'a';
std::string s = "apple";
// compare:
if (s[0] == c) // s[0] is the first character (letter) of the string.
{
std::cout << "A for Apple!" << std::endl;
}
If you have an array/vector of strings, you would access the i'th string's first character as my_str_list[i][0].