find
资源名称:CppPrimer.rar [点击查看]
上传用户:qdkongtiao
上传日期:2022-06-29
资源大小:356k
文件大小:1k
源码类别:
书籍源码
开发平台:
Visual C++
- variable
- //begin{find_word}
- #include <string>
- int main()
- {
- // initialize a string to hold a word to search for
- string search_word;
- cin >> search_word;
- // initialize a bool variable to false
- bool found = false;
- string next_word;
- while ( cin >> next_word ) {
- if ( next_word == search_word )
- found = true;
- }
- //{ shorthand notation for: if ( found == true ) }
- if ( found )
- std::cout << "ok, we found the word" << std::endl;
- else
- std::cout << "nope, the word was not present." << std::endl;
- return 0;
- }
- //end{find_word}