Learning notes of C + +++

Time:2021-2-9

C + + is an intermediate language, which was designed and developed by Bjarne Stroustrup in Bell Labs in 1979. C + + is an object-oriented programming language, which further expands and perfects C language. C + + can run on a variety of platforms, such as windows, Mac operating system and various versions of UNIX.

course: https://www.runoob.com/cplusplus/cpp-tutorial.html

example:

#include  

using  namespace std;

int main()

{

    cout << “Hello,Word!” << end1;

    return 0;

}

You can replace end1 in the above code with “\ n”.

Question:

What’s the difference between “\ n” and end1 in C + +?

“\ n” represents a string whose content is a carriage return. STD:: end1 is a stream operator. The function of output is similar to that of output “\ n”, but it may be slightly different. STD:: end1 outputs a newline character and immediately flushes the buffer.

For example:

std::cout << std::end1;

amount to

std::cout << ‘\n’ << std::flush;

perhaps

std::cout << ‘\n’ ; std::fflush(stdount);

Because of the stream operator<

For output buffered streams (such as cout and clog), if the buffer is not refreshed manually, the output will be refreshed automatically when the buffer is full. However, for cout (relative to file output stream, etc.), buffering is not obvious. But it’s a good habit to use end1 instead of ‘\ n’ if necessary. For unbuffered streams (such as cerr of standard error output), refresh is unnecessary. You can directly use “\ n”.

 

Recommended Today

Practice analysis of rust built-in trait: partialeq and EQ

Abstract:Rust uses traits in many places, from simple operator overloading to subtle features like send and sync. This article is shared from Huawei cloud community《Analysis of rust built-in trait: partialeq and EQ》Author: debugzhang Rust uses traits in many places, from simple operator overloading to subtle features like send and sync. Some traits can be automatically […]