// Finding elements from a vector container #include #include #include #include namespace my{ // utility to print out a vector template void vector_out(const std::vector v){ for(auto x:v) std::cout< v{1.4,1.6,0.2,1.8,0.1,1.5}; // or do many push_back's std::cout<<"original vector\n"; my::vector_out(v); std::cout<<"minimum element = "<<*min_element(v.begin(),v.end())<<"\n"; std::cout<<"maximum element = "<<*max_element(v.begin(),v.end())<<"\n"; // find element with some value auto it = find(v.begin(),v.end(),0.2); // I'd prefer find(v,0.2) if(it==v.end()) std::cout<<"failed to find value\n"; else { std::cout<<"found value "<<*it<<"\n"; // reverse some elements std::cout<<"reverse starting from "<<*it<<"\n"; std::reverse(it,v.end()); // I'd prefer std::reverse(it) my::vector_out(v); } std::cout<<"sorting...\n"; std::sort(v.begin(),v.end()); my::vector_out(v); }