C++は容器の中の最小の最大値を求めます

1013 ワード

// Visual Studio 2015    
//  std::vector    

#include 
#include 
#include  // std::minmax_element
#include     // std::vector

int main(int argc, char *argv[])
{
	std::vector vec{ 2.1, 1.1, 4.1, 3.1 };

	//         
	//   std::pair<:vector>::iterator, std::vector::iterator>    ,   auto  
	auto v = std::minmax_element(vec.begin(), vec.end());
	std::cout << *v.first << std::endl;  // 1.1 -    
	std::cout << *v.second << std::endl; // 4.1 -    

	//      
	//   std::vector::iterator    
	auto min = std::min_element(vec.begin(), vec.end());
	std::cout << *min << std::endl; // 1.1

	//      
	//   std::vector::iterator    
	auto max = std::max_element(vec.begin(), vec.end());
	std::cout << *max << std::endl; // 4.1

	system("pause");
	return 0;
}