Cout and cin are not functions, so what is it?

Typically, in the C programming language, we consider printf and scanf to be functions. when it comes to cout and cin, in C ++, what is it? I mean, they cannot be functions, because they are not followed by brackets, therefore they are not functions. So what are cout and cin - standard input and output functions? Or something else?

+6
source share
3 answers

std::cout and std::cin are global objects of the std::ostream and std::istream respectively, which they overloaded with the operator << and >> . You should read about operator overloading .

  cout << expr ; ~~~~~~ ~~~~ ~~~~~~~~ object op. argument 

This is like calling a function; the function is an overloaded operator and a shortcut for this:

 cout.operator<<(expr); 

or that:

 operator<<(cout, expr); 

depending on overload resolution results

+17
source

cout - an object of type ostream . cin is an object of type istream .

+6
source

These are global variables declared in the <iostream> header <iostream>

+2
source

Source: https://habr.com/ru/post/1268633/


All Articles