C/C++ Arena

Step 5 of 5

Default arguments

Parameters can have default values, used when the caller leaves them out. Defaults go at the end of the parameter list:

void spawn(std::string name, int hp = 100, int armor = 0);
spawn("bot");            // hp 100, armor 0
spawn("bot", 50);        // armor 0

Your turn: write std::string pad(const std::string& s, int width, char fill = ' ') that adds fill characters on the left until the string is width long. Strings already that long are returned unchanged.

Previous: Overloading