Awesome
correct_cpp_hello_cli
Branch | Travis CI | Codecov |
---|---|---|
master |
Correct C++ chapter 'Hello CLI'.
:warning: this course does not work until I've updated the scripts to use GitHub Actions :warning:
Goal
- Write a command-line interface (CLI) application
Prerequisites
- Understand how this course works
- Have written a correct 'Hello world' program
Exercise
Write a command-line interface (CLI) program that writes Hello
to the screen.
If the user has supplied a command-line argument, show it, after adding a space between 'Hello' and the argument. Ignore command-line arguments beyond the first. In all cases, the output should be followed by a newline:
Call to hello_cli | Result |
---|---|
./hello_cli | Hello (with newline) |
./hello_cli world | Hello world (with newline) |
./hello_cli world i_am_ignored | Hello world (with newline) |
This is the code you start with:
main(argc, argv)
{
//Your code here
}
- See run your program with arguments if you need help on this
- argv is a container of raw strings
- argv has argc elements
- argc is never equals to zero
- If argc equals one, just show 'Hello'
- If argc equals two or more, show 'Hello', a space, and the content of argv[1]
- Use (and prefer [1]) std::cout
- Do not use std::endl [2]