Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Sep 25, 2000

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
}

Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date