It is estimated that many people use the computer for the first time through Windows (Microsoft's operating system), and the design of Windows causes many people to think that all programs can be executed correctly by double-clicking them, so a lot of novice children's shoes will encounter some questions:
Why did the program not execute correctly after double-clicking?
How does the program go black?
What did the program tell me to input parameters?
There are many ways to clarify these problems. Let's talk about how Windows executes the program.
How programs are executed on Windows
As far as I know (in order not to say absolutely), there are two main ways to execute programs on Windows: One is double-click; one is executed by command prompt (CMD). In terms of operation, the former requires a mouse, the latter can not need a mouse. As for double-clicking this way, it is estimated that people who have access to Windows will use it, so they don't. How to use the latter way? Very simple, first start the cmd, start the method can have several, I like: windows+r key combination, enter CMD in the input box, hit enter, so do not use the mouse. Such as:
After starting CMD, for example I want to start Notepad to edit a file named Demo.txt, you can enter in cmd: Notepad demo.txt and then hit enter.
The Notepad entered above is the name of the executable program of Notepad, which exists in the path directory of the Windows system (the directory in which the system searches for executable programs), and Demo.txt is a parameter passed to Notepad.
Our own program is how to know the execution parameters of the program
Knowing how to use the command line, how does my program know what parameters to accept? The parameter of the main function of C/s + + is to solve this problem.
Look at the standard definition of the main function:
int main (int argc, char** argv) { return 0;}
The first parameter, ARGC, represents the number of parameters that I passed to the operating system when I started the program, for example, the value of Notepad DEMO.TXT,ARGC is 2.
The second parameter argv the value of the parameter. For example, the argv of Notepad demo.txt is {{"Notepad"},{"Demo.txt"}}.
You can look at this blog post again, and you might understand better.
http://blog.csdn.net/bendanban/article/details/7623209
Notes on program execution under Windows