Extracting a Program's Name

The name of the executable is stored in the string argv[0]. To access it, declare your main() function as follows:

int main(int argc, char ** argv)

Even if the application was called without any parameters from the command-line, C++ ensures that at least one argument, namely argv[0], contains a null-terminated string with the name of the executable file. You can extract it as follows: