This may be a bad question but I would like to know what the -o
called when you have something like
g++ -o hello.out hello.cpp
and how I can implement them in a C++ program
This may be a bad question but I would like to know what the -o
called when you have something like
g++ -o hello.out hello.cpp
and how I can implement them in a C++ program
These are command line arguments.
A command-line argument or parameter is an item of information provided to a program when it is started. A program can have many command-line arguments that identify sources or destinations of information, or that alter the operation of the program.
The -x
, --x
or /x
forms are generally considered options or switches.
The program run determines what is actually done; in C/C++ the arguments are directly accessible in the argv
parameter to the main function. There are are also libraries to make parsing easier.
-o
is an option passed to the compiler g++
. It let give the name of the file to produce. Here it means "compile file hello.cpp
to produce a file called hello.out
".
You can read the manual to find out more: man g++
If you want to know how to use flags like this in your program, you may eg. refer to Arguments to main in C
In short: if you define your main function by int main(int argc, char **argv);
, then a potential -o
flag provided by the user, could be read from argv