Std::distance Include Code Example
Example: std distance
// Calculates the number of elements between first and last. #include <iterator> // std::distance #include <vector> // std::vector #include <algorithm> // Just if you use std::find vector<int> arr = {2,5,3,8,1}; int size = std::distance(arr.begin(), arr.end()); // 5 auto it = std::find(arr.begin(), arr.end(), 8); int position = std::distance(arr.begin(), it); // 3
Comments
Post a Comment