Get the App
SLTechnology News&Howtos  ›  Development  › 

How to analyze the IO flow of C++ system

Shulou Source: shulou.com Published: 2022-06-02 07:30:50 09月25日 Update

This article shows you how to analyze the IO stream of C++ system. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Foreword:

This time, I will explain a small knowledge point, which is also the most common knowledge point: no matter what program iostream; writes, it is bound to use IO stream interaction to understand simple IO stream in detail.

1. Iostream standard library

Definition: the IO interface provided by the standard library for interacting with users

Input stream: cin

Output stream: cout, cerr, clog

One of the differences among the output streams:

1. First of all, there are different output targets. Cerr is mainly used to output error information, and clog is mainly used to output log information.

2. The biggest difference in cerr is that the buffer is flushed immediately, and the output is faster. The other two kinds of output information may be lost when the program crashes.

There are other methods for buffer flushing: std::flush, std::endl

2 、 namespace

Mainly to avoid name conflicts, you can see the following code:

Namespace People1 {void fun () {}} namespace People2 {void fun () {}}

There are two functions with the same name in the above code, and the compilation can be passed, which is what the namespace is for.

When using the function fun (), you need to specify a namespace

There are three ways to use namespaces:

/ / 1, domain parser:: People1::fun (); / / 2, using statement using namespace People1;fun (); / / 3, namespace alias namespace ns1 = People1;ns1::fun ()

Note: std is the namespace of the standard library, and it is also the most commonly used one.

3. The difference between C and C++ output

Printf: intuitive to use, but easy to make mistakes

Cout: not easy to make mistakes, but long to write

Clippers 20 formatting library: a new solution (not commonly used at present)

The above content is how to analyze the IO flow of C++ system. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Output space that is knowledge caching standards systems analysis differences code information content functions common use skills knowledge points programs buffers buffers verbosity Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Docker MySQL Shulou Technology macOS