HOW TO RUN A C++ PROGRAM WITH INPUT AND OUTPUT FILES - there are at least three ways to specify an input file and an output file at run time (1) program can prompt and ask for the name of the file at run time. We will not use this method in CS 330. (2) the command to start the program can redirect the input to come from a file and the output to go to a file. % ./myprog myoutputfile.txt where myprog is the name of our comiled executable file, myinputfile.txt is an input file, and myoutputfile.txt is an output file. The output file will be created as necessary. (3) the program can accept a command-line argument via the argc and argv parameters to main. In this case, the Linix operating system looks at the word(s) after the program name on the command line, e.g. % ./myprog myfile.txt where myprog is our compiled executable file and myfile.txt is a command-line argument). Following is a brief description of options 2 and 3 -------------------------------------------------------- I/O REDIRECTION: - In previous terms, some people have asked about using input and output redirection, for preliminary debugging. On replit g++ myprogram.cpp -o myprogram ./myprogram out1-01.txt On Visual C++ In Project / Settings / Debug / Program Arguments Put this text: out1-01.txt Note: no space after the "<" and ">" symbols for Visual C++. On replit, you can put spaces. ----------------------------------------------------- COMMAND-LINE ARGUMENTS: - For the CS330 project, for Phase 2 and 3 you are required to use command-line arguments. You will pass the name of the input and output files as arguments to your program % ./phase1 in1-01.txt out1-01.txt If you start your program this way, argv[0] will be the C-string "phase1" (or maybe it is "./phase1"), argv[1] will be "in1-01.txt", and argv[2] will be "out1-01.txt". - on Visual C++ In Project / Settings / Debug / Program Arguments Put this text: in1-01.txt out1-01.txt to pass 2 C-strings to the program as argv[1] and argv[2]. - more details are given in a separate file concerning command line arguments. ----------------------------------------------------------