0
Take file name in console
I want to take file name or read file in console like this: some_app.exe file.txt <- read or take this. I not want to only run some_app.exe and on new line: cin >> file, i want to take file name in upper example
1 Réponse
+ 4
Danila Khaminets The command line gets passed into main through its input parameters.
int main(int argc, char *argv[]);
argc - the count of command line strings in argv
*argv[] - the command line string values (C strings, NULL-terminated)
argv[0] will be the program name itself
argv[1], argv[2], ... will be the added elements after the program name.
In your case, argc will be 2; argv[0] will point to "some_app.exe" and argv[1] will point to "file.txt".