Read 2 file in command line.

I'm wondering how can I make the following command works in any code. Can anyone give me an example.
Command:
[cpp_file_path] [input_file_1_path] [input_file_2_path] [output_file]
Can I use argv? Like something below.
1
2
3
  int main(int argc, char* argv[]){
    
  }
I think I don not really get your question.

Anyways, if you want to read in files, or write to them, without using the command line (I am not even sure, this works, I don't know a command line function that could help you), there are many possibilities.

The easiest (IMO) is the C-Filesystem: There are loads of tutorials about that: http://www.mycplus.com/tutorials/c-programming-tutorials/file-handling/

Or you decide on using the C++-Standard Library:

Tutorial on this site: http://www.cplusplus.com/doc/tutorial/files/

If this was not the answer you were looking for, please tell us what you are looking for more precisely.

Cheers

Mokka
Well, I read this page: http://www.cprogramming.com/tutorial/lesson14.html

And I saw that using that code I can open one file in the command line with this command:
[.exe] [other_file]

The [other_file] is saved as argv[1] and the executable file is stored as argv[0]. And I wish to open another file and write whatever I did in the code in the output file.

My command is something like this:
[.exe] [other_file] [another_file] [output_file]

Will this let [another_file] stored as argv[2] and [output_file] stored as argv[3]?
If your program is called prog, you can enter a command line like
prog file1 file2 file3

Declare main() like this:
1
2
3
int main(int argc, char *argv[])
{
}

argc is the number of arguments on the command line. In this case it will be 4. The value are:
1
2
3
4
argv[0] = "prog"
argv[1] = "file1"
argv[2] = "file2"
argv[3] = "file3"


So you can process the arguments with a simple loo. Note that the loop starts at 1 to process the arguments and not the name of the program itself.
1
2
3
for (int i=1; i<argc; ++i) {
    doOneFile(argv[i]);
}
This is what I meant. Sorry my English is not that good. Anyway, thanks for your help, dhayden.
Oooooohh that is what you meant ^^

Sry for not rly being a help :P
Topic archived. No new replies allowed.