devxlogo

Extracting a Program’s Name

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:

 int main(int argc, char ** argv){ const char prog_name = argv[0]; cout << prog_name; // name of .exe file}

See also  Is Machine Learning Automating Creativity in Graphic Design?
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist