Using command line arguments in VS2010

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.