Small Steps VI — Growing into C++
Using tools that already exist
Use tools that already exist.
What you will learn
A library is a collection of tools made for use in programs. The C++ standard library provides common tools across different environments.
Try it
Example · example1.cpp
void small_main()
{
Array<int> numbers = {8, 3, 12, 5};
int smallest = std::min(8, 3);
int largest = std::max(8, 12);
print("Min: ", smallest);
print("Max: ", largest);
}
std::min returns the smaller of two values; std::max returns the larger. The expected output is Min: 3 and Max: 12.
std:: marks a name belonging to the standard library. For now, Small IDE prepares the basic headers you need.
Exercise
Use std::min and std::max on the ints 17 and 42 and print the smaller and larger values.
Exercise starter · exercise1_starter.cpp
void small_main()
{
// print the smaller and larger values using std::min and std::max.
}
Hint
You can put a standard function directly inside print, as in print(std::min(17, 42));.
show solution
void small_main()
{
print(std::min(17, 42));
print(std::max(17, 42));
}