Difference between revisions of "CPP/C++0x/VectorMinMax"
From ProgrammingExamples
< CPP
(→VectorMinMax.cpp) |
Daviddoria (Talk | contribs) m |
||
Line 8: | Line 8: | ||
{ | { | ||
// Vector initialization | // Vector initialization | ||
− | std::vector<int> v = { | + | std::vector<int> v = {10,20,30}; |
auto minmax = std::minmax_element(v.begin(), v.end()); | auto minmax = std::minmax_element(v.begin(), v.end()); | ||
− | std::cout << *(minmax.first) << std::endl; | + | std::cout << *(minmax.first) << std::endl; // outputs '10' |
− | std::cout << *(minmax.second) << std::endl; | + | std::cout << *(minmax.second) << std::endl; // outputs '30' |
return 0; | return 0; |
Latest revision as of 15:02, 12 June 2012
VectorMinMax.cpp
#include <iostream> #include <vector> #include <algorithm> int main() { // Vector initialization std::vector<int> v = {10,20,30}; auto minmax = std::minmax_element(v.begin(), v.end()); std::cout << *(minmax.first) << std::endl; // outputs '10' std::cout << *(minmax.second) << std::endl; // outputs '30' 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")