C++17 STL Cookbook
上QQ阅读APP看书,第一时间看更新

Compiling and running the recipes

All the code in this book has been developed and tested on Linux and MacOS, using the GNU C++ compiler, g++, and the LLVM C++ compiler, clang++.

Building an example in the shell can be done with the following command using g++:

$ g++ -std=c++1z -o recipe_app recipe_code.cpp

Using clang++, the command is similar:

$ clang++ -std=c++1z –o recipe_app recipe_code.cpp

Both the command-line examples assume that the file recipe_code.cpp is the text file containing your C++ code. After compiling the program, the executable binary will have the filename recipe_app and can be executed as follows:

$ ./recipe_app

In a lot of examples, we read the content of entire files via standard input. In such cases, we use the standard UNIX pipes and the UNIX cat command to direct the file content into our app, as follows:

$ cat file.txt | ./recipe_app

This works on Linux and MacOS. In the Microsoft Windows shell, it works as follows:

> recipe_app.exe < file.txt

If you do not happen to run your programs from the command-line shell, but from the Microsoft Visual Studio IDE, then you need to open the dialogue, "Configuration properties > Debugging", and add the "< file.txt" part to the command line of the app that Visual Studio uses for launching.