Home>Article>Backend Development> c++ output statement

c++ output statement

尚
Original
2019-10-25 16:17:36 14267browse

c++ output statement

The C standard library provides a rich set of input/output functions. C's I/O occurs in streams, which are sequences of bytes. If a stream of bytes flows from memory to a device (such as a display, printer, disk drive, network connection, etc.), this is called an output operation.

Standard output stream (cout)

The predefined object cout is an instance of the iostream class. The cout object "connects" to the standard output device, usually the display screen. cout is used in conjunction with the stream insertion operator << as shown below:

#include  using namespace std; int main( ){ char str[] = "Hello C++"; cout << "Value of str is : " << str << endl;}

When the above code is compiled and executed, it produces the following results:

Value of str is : Hello C++

C Depending on the data type of the variable to be output, the compiler selects the appropriate stream insertion operator to display the value. The << operator is overloaded to output data items of built-in types (integer, float, double, string, and pointer).

Stream insertion operator << can be used multiple times in a statement, as shown in the example above, endl is used to add a newline character at the end of the line.

The above is the detailed content of c++ output statement. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn