void TestMaxElement() { vector<int> vi{1,7,9,3,15,6,20}; for (auto i:vi) { cout << i << std::endl; } auto begin = vi.begin()+2; std::cout << *begin << std::endl; //Returns an iterator pointing to the element with the smallest value in the range [first,last) //注意最后一个元素是闭区间 std::cout << "The smallest element is " << *std::min_element(vi.begin(), vi.begin() + 2) << ' '; std::cout << "The largest element is " << *std::max_element(vi.begin(), vi.begin() + 2) << ' '; }