using command line arguments in VS2010Time 2014-07-11 22:20:39 csdn blog Original http://blog.csdn.net/u010839382/article/details/37704553 theme Visual Studio IOS
Programming in Linux is accustomed to using command-line parameters, so the use of VS2010 also tried.
New project, C + + writing program is as follows:
#include <iostream>
#include <fstream>
using namespace std;
int main (int argc,char*argv[])
{
ifstream fin (argv[1],ios::in);//Input mode open file
//ifstream fin;fin.open (argv [1],ios::in);
Ofstream Fout (Argv[2],ios::out|ios::app);//output, append mode open file
//ofstream fout;fout.open (argv[2],ios::out|ios::app);
int C;
while (!fin.eof ())//To determine whether the end of the file
{
c=fin.get ();//character
fout.put (c);//write characters
}
fin.close ();// Close file
fout.close ();
return 0;
}
In order to implement the command line parameter argv[] in your program, you need to set the properties of the project.
Project-> Properties-> debug-> command parameters, enter A.txt b.txt
Also, for ease of testing, set the working directory to the desktop.
Project-> Property-> Debug-> working directory, set to desktop
You can compile the execution program.
The applet implements a copy of the file. namely A.txt-->b.txt