📜  标准距离 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:47.365000             🧑  作者: Mango

代码示例1
// Calculates the number of elements between first and last.

#include                                          // std::distance
#include                                              // std::vector
#include                                // Just if you use std::find

vector 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