Use command line parameters in vs2010

Source: Internet
Author: User
Programming in Linux is used to using command line parameters, so I tried it when using vs2010.

Create a project and write the following program in C ++:

# Include <iostream> # include <fstream> using namespace STD; int main (INT argc, char * argv []) {ifstream fin (argv [1], IOS :: in); // open the file in input mode // ifstream fin; Fin. open (argv [1], IOS: In); ofstream fout (argv [2], IOS: Out | IOs: APP ); // output and append the file. // ofstream fout; fout. open (argv [2], IOS: Out | IOs: APP); int C; while (! Fin. EOF () // determines whether the end of the file is {c = fin. get (); // get the character fout. put (c); // write character} fin. close (); // close the file fout. close (); Return 0 ;}

To implement the use of the command line parameter argv [] in the program, you need to set the properties of the project.
Project-> properties-> debugging-> command parameters, enter a.txt B .txt
At the same time, to facilitate testing, set the working directory as the desktop.

Project-> properties-> debugging-> working directory, set to desktop


Compile and execute the program.
This applet Copies files. 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.