Description of the variable (INT argc, char * argv []) in the main function

Source: Internet
Author: User
Tags first string

Labels: style blog color OS AR for file 2014 sp

You can see a piece of video processing code on opencv, but the running box copied to vs is always flashed back. Check whether the EXE file should be run directly under the command, it mainly involves the significance of the argc and argv parameters in the main function.

Argc: an integer used to count the number of command line parameters that you send to the main function when running the program.

* Argv []: String Array, used to store a pointer array pointing to your string parameters. Each element points to a parameter.

Argv [0] points to the full path name of the program running

Argv [1] points to the first string after the program name is executed in the doscommand line

Argv [2] points to the second string after the execution program name

Argc refers to the number of input parameters in the command line. argv stores all command line parameters. Assume that one of my programs is video_test.exe. If you run this program on the command line (you should first run the CD command in the command line to enter the directory where the video_test.exe file is located), the files to be processed include v1.avi and v2.mpg. The command is:

Video_test.exe v1.avi v2.mpg

The value of argc is 3, argv [0] is "video_test.exe", argv [1] is "v1.avi", and argv [2] is "v2.mpg ".

That is to say, if the program is directly compiled and run in Vs, argc only executes the EXE

Int main (INT argc, char ** argv) {// declare iplimage pointer iplimage * pframe = NULL; iplimage * pfrimg = NULL; iplimage * pbkimg = NULL; cvmat * pframemat = NULL; cvmat * pfrmat = NULL; cvmat * pbkmat = NULL; cvcapture * pcapture = NULL; int nfrmnum = 0; // create a window cvnamedwindow ("video ", 1); cvnamedwindow ("background", 1); cvnamedwindow ("foreground", 1); // arrange the cvmovewindow in sequence ("video", 30, 0 ); cvmovewindow ("background ", 360, 0); cvmovewindow ("foreground", 690, 0); If (argc> 2) {fprintf (stderr, "Usage: bkgrd [video_file_name] \ n "); return-1;} // open the camera if (argc = 1) if (! (Pcapture = cvcapturefromcam (-1) {fprintf (stderr, "can not open camera. \ n "); Return-2;} // open the video file if (argc = 2) if (! (Pcapture = cvcapturefromfile (argv [1]) {fprintf (stderr, "can not open video file % s \ n", argv [1]); Return-2 ;}

Description of the variable (INT argc, char * argv []) in the main function

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.