How to calculate the number of elements between first and last in a list with C++

1 Answer

0 votes
#include <iostream>
#include <iterator>
#include <list>

using std::cout;
using std::endl;
using std::list;

int main()
{
	list<int> lst = { 1, 2, 3, 4, 5, 6 };

	cout << distance(lst.begin(), lst.end());

	cout << endl;

	return 0;
}


/*
run:

6

*/

 



answered Apr 22, 2018 by avibootz
...