comparing std::vector<string> to std::char

let's say I have a vector of strings.

vector<string> words;

and I want to compare each character in a word from that vector of strings.

how can I do that?

For example:

1
2
3
4
5
vector<string> words;
for (int i = 0; i < words.size(); i++)
{
	if(words[i] == 'A')
}


Now I know this doesn't work because I can't compare a string to a char. But I want to loop through the characters of a word[i] and compare it to a char.

Is that feasible?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
 // http://www.stroustrup.com/C++11FAQ.html#for

for( const std::string& str : words ) // for each string in the vector 'words'
{
    for( char c : str ) // for each char in the string
    {
        if( c == 'A' )
        {
            // do some thing
        }
    }
}
Topic archived. No new replies allowed.