To fully master the technology of C ++ applications, you must understand the structure, statements, variables, functions, preprocessing instructions, input and output of C ++, in any case, you should ensure the security of your system and never allow any other script programs to access internal programs.
Next, we also use conditional operators to output another sentence. Remember that, even if we do not pass any parameters from the program execution command line, the main function argv [] parameter also contains a value. Similarly, if we pass two parameters to the program from the command line, the program will output the following information:
- Theseargumentsare:
Finally, the main function outputs each parameter input from the command line one by one. It uses a simple for (;) loop statement, this function outputs parameter values one by one based on the number of parameters. If we pass two parameters "first" and second "to the program, the output of the for Loop is as follows:
- [1]?first
- [2]?second
The above is a simple description of the C ++ application. Its function is very simple, that is, the parameters passed in by the command line are displayed on the output screen using the cout function. Next, we will compile this. cpp file. If you are on windows, telnet to the server you are using.
Here, we use the G ++ compiler provided on most Unix machines to compile this source file. To ensure that your machine has installed G ++, run the following command: whichg ++. If G ++ has been installed, Unixshell displays the full path of G ++. If it is not installed, it will prompt you to say "commandcouldn 'tbefound". You can download it to G ++ here.
With this command, we compile the. cpp file into a target file containing the machine code. Through ls? A command, you can find a new file sampleapp. o appears in the local directory. This is the result of the. cpp source file being compiled into a machine code. But what we finally want is an executable file, because we need to enter the following G ++ command:
- Youpassed3arguments.
- Theseargumentsare:
Now, the executable C ++ application is generated. Next we will generate a PHP tutorial program that can access this program through a web browser.
To call our C ++ application over the Internet, we need to generate a PHP script program. This PHP script contains a Form that allows you to input parameters that can be passed to the Sampleapp program. The PHP script code is not listed here because it is too long. You can download it at the address below if necessary.
First, check whether the variable $ submit has a value. The value of this variable $ submit is passed after the Form is submitted after the program. The default value is null. Symbol @ is used to ignore related error messages when the value of variable $ submit does not exist.
Because the variable $ submit is empty by default, the code in else {} is executed at the beginning, and a Form is displayed in the browser. The action attribute of Form is set to variable $ PHP_SELF, that is, this page is returned after the Form is submitted. At the same time, the Form contains a text entry.
This is a command line parameter that allows the user to input the command line parameters to be passed to the C ++ application. Once we enter the execution command and submit the form, the variable $ submit is the name of the Go button) will get a value, so that the PHP tutorial will execute code between if.
- if($args=="")
- echo"<h1>Youdidn'tenteranyarguments.</h1>";
- else
- {
- echo"<h1>SampleAppResult</h1>";
- $command="/htdocs/sampleapp".escapeshellcmd($args);
-
- passthru($command);
- }
The variable $ args is automatically generated. Its value is the value passed by text entries in the Form. If no information is entered, the program will simply tell the user that no value is entered.
- Differences between standard input implementation methods in C and C ++
- How does the C ++ compiler allocate storage space for Const constants?
- Basic Conception and method of C ++ Class Library Design
- Several Methods for converting C ++ Language
- How to better compile C ++ code