I/O Streaming class library (i)

Source: Internet
Author: User
I/OThe input and output of data (Input/output I/O) to standard input devices and standard output devices is referred to as the standard I/O heap of files on the external disk of the input and output abbreviation for file I/O to memory specified in the string storage space of the input output short for string I/O FlowThe process of data input and output, which can be visualized as the operation of the stream to fetch data from the stream called "Fetch" (input) operation to add data to the stream called "Insert" (output) operation standard input output stream file stream string stream Stream Class Library inheritance system

The stream library has two parallel base classes: Streambuf and iOS classes, where all stream classes provide a low-level operation of the buffer in one of the base class Streambuf classes: Setting buffers, manipulating buffer pointers, depositing/fetching characters to buffers, Ios_base, iOS class record flow states, Supports formatted or unformatted conversion of buffer input/output to STREAMBUF Streambuf: use strings to save character sequences. Extended streambuf in buffer extraction and insert management Filebuf: Save a string sequence with a file. Includes opening files, reading/writing, finding characters four input output objects C + + defines four class objects for user standard I/O operations: CIN, cout, Cerr, and clog
CIN is the object of the IStream stream class, representing the standard input device keyboard, and the latter three objects for the Ostream stream class cout represent the standard output device monitor Cerr and clog have the same meaning, representing the operation of the error message output device monitor Ostream stream operator<<
Can be output continuously, because the << return is cout put ()
Output a single character returns a reference to a Ostream object Cout.put (' H '). Put (' I ') write ()
Write (buf, Len) write () Returns the action//char operation of a Ostream object's reference Cout.write (buf, Len) Buf[len IStream] operator>> Stream Get ()
-Read a single character
-Returns an integer (Ascall code value of the input character) getline () read () Peek () putback ()

Get ()

     1. Read single character
     2. Returns an integer (the input character's ascall code value)

Get (cahr&)

     1. Returns a single character
     of 2. Returns a reference to a IStream object
    #include <iostream>

    using namespace std;

    int main (void)
    {
        char ch1, CH2;
        Cin.get (CH1). get (CH2);
        cout << ch1 << "  " <<ch2<< Endl;
        return 0;
    }

getline ()

     1. read one line (hit Enter)
     2. Returns the reference to the IStream object
     3. Getline () and >>:
         char string1[256];
         Cin.getline (string1, 256); Get a whole line
         cin>>string1;   Stop at the Blank
    #include <iostream>

    using namespace std;

    int main (void)
    {
        char buf[10] = {0};
        Cin.getline (BUF, 9);
        cout << buf << Endl;
        return 0;
    }

Read ()

     1. Read (buf, Len)
     2. Returns a reference to a IStream object
     3. To the blank word Fu Zhao Read no error
     4. Must read Len Word character character stop
    #include <iostream>

    using namespace std;

    int main (void)
    {
        char buf[10] = {0};
        Cin.read (BUF, 5);
        cout << buf << Endl;
        return 0;
    }

Peek ()

     View without reading

putback ()

     Add a character to the stream
#include <iostream>

using namespace std;

int main (void)
{
    char c[10],c2,c3;
    C2 = Cin.get ();
    C3 = Cin.get ();
    Cin.putback (C2);
    Cin.getline (c, 9);
    cout << c << Endl;
    return 0;
}

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.