I am studying declaration, definition and initialization in C++.
I built this proof of concept and I didn't understand compiler's error meaning.
The source code snippet:
#include <iostream>
int main ()
{
std::cin >> int input_value;
return 0;
}
When attempting to compile:
% g++ -Wall -o p44e1 p44e1.cc
p44e1.cc:5:18: error: expected '(' for function-style cast or type construction
std::cin >> int input_value;
~~~ ^
1 error generated.
A function body consists of zero or more statements.
There are several kinds of statements. We only care about two here:
A declaration statement, e.g. int input_value;
An expression statement. That is, e;
. Where e
is an expression, meaning "operands connected with operators, or an individual operand".
std::cin >> input_value;
would be an expression statement, where std::cin >> input_value
is an expression (std::cin
and input_value
are operands, and >>
is an operator).
So std::cin >> int input_value;
is outright invalid. int input_value;
must be a separate statement, but you tried to embed it into an other (expression) statement.