-5

I'm used to program in Python, and since in Python, all are objects, it is totally acceptable when at the end of a variable, a . operator is used to access the method of a class. But in C++, let say for something like std::cin.getline(), is this some kind of accessing the member function of cin?

Is cin some kind of a class or a struct?

3 Answers3

6

Once you type:

#include <iostream>

the corresponding headerfile is inserted there. One line of this file reads

extern istream cin;

So as you see you have an object of type istream accessable from anywhere in the file with the include statement.

So your guess that cin is an instance of a class was right and the dot operator calls the getline method of that object/class.

Source: http://www.cplusplus.com/reference/iostream/cin/

jaaq
  • 1,188
  • 11
  • 29
4

cin is indeed an instance of the class std::istream.

Thomas B Preusser
  • 1,159
  • 5
  • 10
2
std

Is the namespace

cin

Is an object from the istream class

getline

Is a method from the cin class.

Edward Alexander
  • 111
  • 1
  • 2
  • 12