get path

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • saharit
    New Member
    • Mar 2011
    • 16

    get path

    hi all i want to get the path of the file that i want to open it in argument of main() function how can i do it?
  • Alex Bránya
    New Member
    • Apr 2011
    • 7

    #2
    Here is a code, if I'm right:

    Code:
    #include <iostream>
    using namespace std;
    
    int main(int argc, char* argv[]) {
       cout << argv[0];
       return 0;
    }

    Comment

    • saharit
      New Member
      • Mar 2011
      • 16

      #3
      thanks Alex but where i put my path of file ? like this c:\document\d.d oc to open this file?

      Comment

      • Alex Bránya
        New Member
        • Apr 2011
        • 7

        #4
        Sorry that I misunderstood your question.

        So you want to open a file in your program, and you would pass the filename as an argument to your executable, am I right?


        You can do it in a command line, or a batch file, or
        even with a call from other program. If you want to do
        from your program, it's possible too, but a bit "harder" :)

        The simple method is from command line:
        Code:
        yourprogram.exe  "pathname"

        Comment

        • saharit
          New Member
          • Mar 2011
          • 16

          #5
          yes, u right but where is the argument that i use :(?

          Comment

          • Alex Bránya
            New Member
            • Apr 2011
            • 7

            #6
            All arguments of your program in argv.
            The argv[0] argument is automatically filled up
            with the program's path.
            The first argument you passed to your exe in command line
            will be in argv[1].
            The second one is in argv[2] and etc.

            Comment

            • saharit
              New Member
              • Mar 2011
              • 16

              #7
              in turbo c++ how can i define aegument in RUN Menu?

              Comment

              • Alex Bránya
                New Member
                • Apr 2011
                • 7

                #8
                ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄
                Program Arguments dialog box
                ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀
                The Program Arguments dialog box is where you
                type in command-line arguments for your
                running programs exactly as if you had typed
                them on the DOS command line.


                ┌─ Arguments ─────────────── ────────── ─┐
                │ │
                └────────────── ─────────────── ─────────┘
                The Arguments input box is where you enter
                the arguments that you want Turbo C++ to pass
                to your running program.



                It's from Turbo c++ Run->arguments->help

                Comment

                Working...