find
来自「经典C++入门之作C++primer 4th 源码」· 代码 · 共 29 行
TXT
29 行
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}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?