HomeLinuxWhat's cout in C++ Language

What’s cout in C++ Language


C++ is an especially helpful programming language that gives a variety of options to work with enter and output. Amongst these options, the cout is among the most generally used ones. Customers can print or output knowledge within the console window.

Comply with this text’s pointers if you wish to be taught concerning the cout operate in C++ programming language.

What’s cout in C++ Language

cout is a mix of two phrases one is c which is named ‘character’ and the opposite is out which is called ‘output’ in C++. It’s a built-in operate in C++ used for displaying textual content, numbers, floating factors, and different characters on the output display. It makes use of the built-in C++ “iostream” header file to show the characters on the output display. With out declaring the header file, you received’t be capable to use the cout operate in your program.

The next is the syntax to make use of cout in C++ programming language.

Within the above syntax, “cout” is the article, << signal signifies insertion operator, whereas “data_to_print” is the user-defined knowledge {that a} consumer desires to output on the console window.

The next are some C++ programming language examples of learn how to use cout.

Instance 1

A easy instance of displaying the message on the display utilizing cout in C++ is as follows:

#embody <iostream>

utilizing namespace std;

int essential ()

{

cout << “Hello, how are you “;

}

Within the above instance, you will note cout is utilized in the principle operate with the “iostream” header file, and it’ll print the message enclosed within the citation marks.

Output

Instance 2

Let’s observe up with one other instance of utilizing cout operate to print values of two integers in C++.

#embody <iostream>

utilizing namespace std;

int essential () {

  int x, y;

cout << “Enter two digits and add them:”;

cin >> x >> y;

cout << “Worth of the first digit is “ << x << endl

<< “Worth of 2nd digit is: “ << y << endl

<< “Sum of each digits:”<<x+y << endl;

  return 0;

}

Within the above code we initialize two variables and get these values from the consumer after which utilizing a single cout we confirmed the 2 digits and their sum.

Output

Instance 3

You may as well use a unique sample of cout in C++, which is “std::cout” which works equally to cout.

#embody <iostream>

utilizing namespace std;

inline int sq (int len){

  return len*len;

}

int essential () {

std::cout << “Sq. size: “

<<sq (100) << std::endl;

  return 0;

}

Within the above program, we made a operate the place we use inline int sq (int len) to return the size utilizing len of the sq variable. In the principle operate, we name member features and present outcomes utilizing std::cout.

Output

Conclusion

In C++ programming the cout is used to show knowledge to the console. Its use is easy that requires solely << signal adopted by the information to print. It makes use of the iostream header file, which is a should for applications that output knowledge in C++ applications. Within the above pointers, one can find a number of examples that may aid you implement cout in C++ programming language.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments