Created
July 22, 2015 01:42
-
-
Save krysseltillada/f79fc81b0d3a044506f4 to your computer and use it in GitHub Desktop.
std::distance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
int main () | |
{ | |
std::vector <int> vec = {22, 33, 2, 1, 2, 5}; | |
int i = 2; | |
for (std::vector <int>::iterator it = vec.begin(); it != vec.end(); ++it) { | |
if (*it == i ) { | |
std::cout << i << " was found at element " << std::distance(vec.begin(), it) << std::endl; | |
break; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment