-2

A very short program

#include <iostream>
using namespace std;

int main()
{
    cin>> int x;

    return 0;
}

it's not compiling, why can't declare after cin?

xoxocoder
  • 1
  • 1

2 Answers2

1

You first have to declare a variable before using it. Or in other words: Variables have to be in scope when using them. That's the way it works in C++.

Striezel
  • 3,497
  • 7
  • 20
  • 35
0

cin is the object in c++ of class istream. It is Used to accept the input from input devices like keyboard and int x; is declaration of variable i.e. allocating the space where our number from input stream will get stored.>> is extraction operator which receives the stream.So declaration and taking input are 2 different things. 1) allocate memory(int x)2)write into it. These 2 things won't happen together.

Dharman
  • 26,923
  • 21
  • 73
  • 125