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?
get path
Collapse
X
-
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; } -
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
-
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
-
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄
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->helpComment
Comment