First of all, we use the two global objects Cin and cout, the following excerpt from MSDN:
Can then extract values from CIN or wcin to read the standard input. The rules for doing so are outlined in the description of the class Basic_istream class. You can also inserts values to cout or wcout to write the standard output. The rules for doing so are outlined in the description of the class Basic_ostream class.
As you can see, CIN is a IStream object that can extract data from standard input, and cout is a Ostream object that can output data to standard output.
What is standard input and standard output? It may not be easy for us to understand, after all, this is the concept of the character interface, and we started to touch the computer is already the universal Windows graphical interface of the operating system. But the Windows operating system provides us with a simulation of the DOS character interface of the program CMD, let us have a general understanding of this. In Linux, it's easier to say this: when executing a shell command, three standard files are opened by default, i.e. standard input files (stdin), usually corresponding to the keyboard of the terminal, standard output files (stdout), and standard error output files (stderr). All two files correspond to the screen of the terminal. The process will get the input data from the standard input file, output the normal output data to the standard output file, and send the error message to the standard error file.
That's better, because when we write a Win32 console application under Windows, our program is similar to the commands that Linux executes in the shell, So this program, of course, can be executed with parameters (that is, the parameter int argc and char* argv[of the main function), and the concept of a standard input buffer and a standard output buffer. Just when we first started learning the programming language in Windows, we always use some graphical interface IDE (such as vc++6.0 is my Enlightenment IDE), so the operation mechanism of this program is not very clear, only know to press the button to automatically complete the compilation, connection, Open a CMD and run the program we wrote directly.
With the concept of standard input and output (preferably as a device file as in Linux), the next step is to say how this cin and the cout are completing the input and output mechanism. First take a look at the following example:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
int j = 0;
while (++j>0) for (int i=0;i>0;i++);
String str;
Cin >> str;
cout << str << endl;
System ("pause");
}