C++ examples for STL Algorithm:distance
Computing the Number of Elements in a Container with algorithm distance template function
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() {/*from ww w . java 2 s . co m*/ vector<int> v; v.push_back(0); v.push_back(1); v.push_back(2); cout << v.size() << endl; cout << distance(v.begin(), v.end()) << endl; }