The purpose of this lab is to get familiarised with creating simple programs and projects in C++.
Now copy-paste it into a new project, compile it, and execute it. Or, if you have a bash terminal (Linux/Mac/Windows with WSL + Ubuntu), type (copy-paste actually, to ensure there are no typos!) the following:
export CXXFLAGS='-g -std=c++20 -pedantic -Wall -Wpointer-arith -Wwrite-strings -Wcast-qual -Wcast-align -Wformat-security -Wformat-nonliteral -Wmissing-format-attribute -Winline -funsigned-char'
echo "export CXXFLAGS='-g -std=c++20 -pedantic -Wall -Wpointer-arith -Wwrite-strings -Wcast-qual -Wcast-align -Wformat-security -Wformat-nonliteral -Wmissing-format-attribute -Winline -funsigned-char'" >> ~/.bashrc |
Note: the first line defines CXXFLAGS
(flags to pass to the C++ compiler) for the current terminal session,
while the second one stores these settings inside your terminal
initialisation file (called "~/.bashrc"), so that you don't have to type them again.
These flags are for the GNU C++ compiler (g++).
make hello
|
This will create an executable file called hello, which you can run by typing
./hello |
On lab Windows PCs, make is called "mingw32-make" (see the instructions for using C++ in the labs) and of course we'd need to use a backslash instead of a slash when running hello, since Windows uses backslashes to separate folders on a path instead of slashes that Unix uses:
.\hello |
If you make any changes, you’ll need to type “make hello” again before running the new version.
./words <file
|
where file is some text file; words.cc itself will do.
Note that to terminate input that you're typing yourself at the terminal,
you need to type the End-of-File (EOF) character on a single line at the
terminal.
On Windows terminal, that's Control-Z. On Linux/Mac/Windows + WSL + Ubuntu
that's Control-D.