max value of vector

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 8 Exercise 10
Using std_lib_facilities.h by Bjarne Stroustrup.

main.cpp main file

[code language=”cpp”]
// Philipp Siedler
// Bjarne Stroustrup’s PP
// Chapter 8 Exercise 10

#include "std_lib_facilities.h"

vector<int> myVec{ 1, 2, 5, 4, 1, 8, 2, 3, 4, 9 };

void maxv(vector<int>& v) {
sort(v);
cout << v[v.size() – 1] << "\n";
}

int main()
try
{
maxv(myVec);

keep_window_open();
}
catch (runtime_error e) {
cout << e.what() << "\n";
keep_window_open();
}
catch (…) {
cout << "Exiting\n";
keep_window_open();
}
[/code]

Output:
9
Please enter a character to exit

Newsletter Updates

Enter your email address below to subscribe to our newsletter

Leave a Reply

Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124