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

Source: Internet
Author: User

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

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 ;}

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.