Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting the error "cin does not name a type"

While trying to write this code, I get an error "cin doesnt name a type". I don't know what the problem is exactly and I tried to write "using namespace std;" but it gave the same error.

Here's the code

#include<iostream>

namespace myStuff {

    int value = 0;

}

using namespace myStuff;

int main {

    std::cout << "enter integer " << ;
    std::cin >> value;
    std::cout << "\nyouhaveenterd a value" << value ;

    return 0;

}

Here's the compilation error :

: extended initializer lists only available with `-std=c++0x` or `-std=gnu++0x` [enabled by default]|
: expected primary-expression before ‘;’ token|
 expected `}` before `;` token|
 `cin` does not name a type|
: `cout` does not name a type|
: expected unqualified-id before `return`|
: expected declaration before `}` token|
||=== Build finished: 6 errors, 1 warnings ===|
like image 971
Ahmed Sherif Avatar asked Dec 27 '22 13:12

Ahmed Sherif


2 Answers

int main{

should be

int main(){

and

std::cout << "enter integer " << ;

should be

std::cout << "enter integer ";
like image 109
Luchian Grigore Avatar answered Jan 10 '23 04:01

Luchian Grigore


On this line:

std::cout << "enter integer " << ;

There's no corresponding operand to make the statement syntactically valid. That's probably the source of your errors.

like image 43
David G Avatar answered Jan 10 '23 04:01

David G