⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arr_find.cpp

📁 不错书对C++/C程序员很有用的大家不要错过.
💻 CPP
字号:
#ifdef __BCPLUSPLUS__
#include <iostream.h>
#include <algorith.h>
#else
#include <iostream>
#include <algorithm>
#endif

using namespace std ;

void main(void)
 {
   const int ARRAY_SIZE = 8;
   int IntArray[ARRAY_SIZE] = { 1, 2, 3, 4, 4, 5, 6, 7 };
   int *location ;	//stores the position of the first matching element.
   int i;
   int value = 4;

   // print content of IntArray
   cout << "IntArray { ";
   for (i = 0; i < ARRAY_SIZE; i++)
	   cout << IntArray[i] << ", ";
   cout << " }" << endl;

   //Find the first element in the range (first, last + 1)
   //that matches value.
   location = find(IntArray, IntArray + ARRAY_SIZE, value);
   
   //print the matching element if any was found
   if (location != IntArray + ARRAY_SIZE)	//matching element found
	   cout << "First element that matches " << value << " is at location "
	   << (location - IntArray) << endl;
   else										// no matching element found
	   cout << "The sequence does not contain any elements with value " << value << endl;
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -