Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,675 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,203 people online right now. Registration is fast and FREE... Join Now!




how to get the filename of the current program ?

 
Reply to this topicStart new topic

how to get the filename of the current program ?

jesh_think
post 31 Aug, 2007 - 07:42 PM
Post #1


New D.I.C Head

*
Joined: 27 Jul, 2007
Posts: 4


My Contributions



i am going to desgn a program for which current (Running program)
programs filename (.cpp)is needed needed ..........

i know in java it easy we can get using getCodeBase() URL........

i dont know how to proceed here .
can any one direct me through
please help me


jesh
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 31 Aug, 2007 - 10:08 PM
Post #2


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,905



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


The 0th Command-line Argument would contain the path of the executable file (but not the source code file).

Since I'm assuming that you need the path+filename of the current program, this example should show you how to obtain it:
CODE
#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
    cout<<argv[0];
    return 0;
}
User is offlineProfile CardPM

Go to the top of the page

jesh_think
post 3 Sep, 2007 - 08:05 AM
Post #3


New D.I.C Head

*
Joined: 27 Jul, 2007
Posts: 4


My Contributions


CODE
#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
    cout<<argv[0];
    return 0;
}


though this gives output .....
OUT\FILENAME.EXE in my turboc++
i 'll make up my project
thanx
User is offlineProfile CardPM

Go to the top of the page

spacetimer
post 3 Sep, 2007 - 05:32 PM
Post #4


New D.I.C Head

*
Joined: 3 Sep, 2007
Posts: 1


My Contributions


use the MACRO __FILE__
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 06:26AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month