Take file name in console | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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

15th Dec 2022, 12:44 PM
Danila Khaminets
Danila Khaminets - avatar
1 Resposta
+ 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".
15th Dec 2022, 3:13 PM
Brian
Brian - avatar