1.先上代码:
#include <iostream> //std::cout
#include <iterator> //std::distance
#include <list> //std::list
using namespace std;
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
list<int> mylist;
for (int i = 0; i < 10; i++)
{
mylist.push_back(i);
}
list<int>::iterator first = mylist.begin();//指向元素0
list<int>::iterator last = mylist.end();//指向元素9之后的位置
//获取[first,last)范围内包含元素的个数
cout << "distance()=" << distance(first, last);
getchar();
return 0;
}
编译失败,报错如下: