Computing the Number of Elements in a Container with algorithm distance template function - C++ STL Algorithm

C++ examples for STL Algorithm:distance

Description

Computing the Number of Elements in a Container with algorithm distance template function

Demo Code

#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;
}

Result


Related Tutorials