CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2001
    Posts
    745

    Getting Filename

    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..

  2. #2
    Join Date
    Jun 2002
    Location
    Letchworth, UK
    Posts
    1,020
    In main, you could save the arguments in a global variable or stuff it away in some static class initialization.
    Succinct is verbose for terse

  3. #3
    Join Date
    Oct 2001
    Posts
    745
    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.

  4. #4
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347
    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:
    Code:
    int g_variable;
    In x.cpp:
    Code:
    extern int g_variable;
    --Paul

  5. #5
    Join Date
    Oct 2001
    Posts
    745
    That worked ..Thanks...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured