-3
#include <iostream>

using namespace std;

int main()
{
    string name;
    cout << "What is your name ? ";
    cin >> name;
    cout << "Your name is " << name << endl;

    return 0;
}

I don't get what exactly is happening in this code. I mean cout and cin aren't functions and you put either << or >> front of them and that's going to output or input but how?

noname
  • 13
  • 5
  • 1
    https://en.cppreference.com/w/cpp/language/operators – KamilCuk Jun 20 '20 at 14:31
  • There are many other things in C++ apart from functions dude!! You yourself have used the term operator. These are the operators written for filestreams. – brc-dd Jun 20 '20 at 14:33
  • This is explained in every, and I mean, every C++ textbook, which is what you should consult for basic information, like this. Unfortunately, stackoverflow.com is not a replacement for a C++ textbook. – Sam Varshavchik Jun 20 '20 at 14:48
  • `cout` and `cin` are instances of some classes. `<<` and `>>` are operators, just like `+` and `/`. When applied to integers, `<<` and `>>` do bit shifting (look up "bit shift operators"). But when you're dealing with classes, you can specify what exacly each operator should do if applied to a class instance; this is called "operator overloading". `<<` and `>>` are overloaded to do input/output when used with `cin`/`cout`. If all of this doesn't make sense for you, then just ignore it for now, and consider `cin >>`/`cout <<` to be magical incantations. – HolyBlackCat Jun 20 '20 at 15:40

1 Answers1

0

Apart from functions, C++ has these things called operators.

Some other examples of operators include +, -, *, and /. The operators in question are called shifting operators, and apart from cout and cin, they are also used for filestram I/O.

You can also define your own operators for classes (called operator overloading).

tersrth
  • 861
  • 6
  • 18