Como funciona find() en este código?
Publicado por Lucas (1 intervención) el 09/09/2019 15:31:53
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <algorithm> //for find()
using namespace std;
int arr[] = { 11, 22, 33, 44, 55, 66, 77, 88 };
int main()
{
int* ptr;
ptr = find(arr, arr+8, 33); //find first 33
cout << "First object with value 33 found at offset "
<< (ptr-arr) << endl;
return 0;
}
Mi probema es por qué (ptr-arr) devuelve el número encontrado correcto.
Valora esta pregunta


0