find_if.cpp
来自「本课程主要介绍面向对象程序设计的方法和c++语言的基本概念。以c++语言中的面向」· C++ 代码 · 共 29 行
CPP
29 行
// find_if.cpp
// searches array of strings for first name that matches "Don"
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
//--------------------------------------------------------------
bool isDon(string name) // returns true if name=="Don"
{
return name == "Don";
}
//--------------------------------------------------------------
string names[] = { "George", "Estelle", "Don", "Mike", "Bob" };
int main()
{
string* ptr;
ptr = find_if( names, names+5, isDon );
if(ptr==names+5)
cout << "Don is not on the list.\n";
else
cout << "Don is element "
<< (ptr-names)
<< " on the list.\n";
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?