Click to See Complete Forum and Search --> : Getting Filename


Kohinoor24
September 27th, 2002, 04:58 AM
Hi all,

Iam outputting Data into an ofstream file.
The path & filename of the output file is given in the program argument.

So In main() Function in main.cpp,I will get the filename,But Iam opening my output file in some other file(x.cpp) & I want to create the output file in this file only .I dont want pass the filename through functions().

Is there any other way to get the "File name " in x.cpp?

Thanks in advance..

cup
September 27th, 2002, 05:20 AM
In main, you could save the arguments in a global variable or stuff it away in some static class initialization.

Kohinoor24
September 27th, 2002, 07:52 AM
If IAM Declaring it as a global variable in main.cpp,How will I access it in my x.cpp.I dont want to give a main.h in my x.cpp file.

PaulWendt
September 27th, 2002, 07:56 AM
To access a variable in ONE module even though the variable is
defined in another, as long as the modules are linked, you can
use the extern keyword.

In main.cpp:

int g_variable;


In x.cpp:

extern int g_variable;


--Paul

Kohinoor24
September 27th, 2002, 08:00 AM
That worked ..Thanks...