C + + IOStreams usage details (ii) standard input and output

Source: Internet
Author: User
Tags include linux

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

Related Article

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.