Difference between revisions of "CPP/C++0x/VectorMinMax"
From ProgrammingExamples
< CPP
Daviddoria (Talk | contribs) (Created page with '==VectorMinMax.cpp== <source lang="cpp"> #include <iostream> #include <vector> #include <algorithm> int main() { // Vector initialization std::vector<int> v = {1,2,3}; st…') |
(→VectorMinMax.cpp) |
||
Line 10: | Line 10: | ||
std::vector<int> v = {1,2,3}; | std::vector<int> v = {1,2,3}; | ||
− | + | auto minmax = std::minmax_element(v.begin(), v.end()); | |
std::cout << *(minmax.first) << std::endl; | std::cout << *(minmax.first) << std::endl; |
Revision as of 15:06, 20 July 2011
VectorMinMax.cpp
#include <iostream> #include <vector> #include <algorithm> int main() { // Vector initialization std::vector<int> v = {1,2,3}; auto minmax = std::minmax_element(v.begin(), v.end()); std::cout << *(minmax.first) << std::endl; std::cout << *(minmax.second) << std::endl; return 0; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) PROJECT(VectorMinMax) ADD_EXECUTABLE(VectorMinMax VectorMinMax.cpp ) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++0x")