12345678
for (int v = 0; v <= word_list.size(); v++) { for (int j = 0; j < word_list.size(); j++) { if (word_list[v][j] == letter_guess) { } } }
1234567891011
string word_list="abcd"; char letter_guess='a'; for (int v = 0; v <= word_list.size(); v++) { if (word_list[v] == letter_guess) { cout << word_list[v] << " Match found at " << v << endl; } }
12345678910111213141516171819202122
#include <iostream> #include <string> #include <vector> int main() { const std::vector<std::string> words { "All", "happy", "families", "are", "alike;", "each", "unhappy", "family", "is", "unhappy", "in", "its", "own", "way." } ; const char letter = 'y' ; // http://www.stroustrup.com/C++11FAQ.html#for for( const std::string& str : words ) // for each string str in the vector { // http://en.cppreference.com/w/cpp/string/basic_string/find (4) if( str.find(letter) != std::string::npos ) // if str contains the letter { // do something. say, print out the string std::cout << str << '\n' ; } } }