Why aren't cin>> and cout<< working?????

Don't know why this stuff isn't working. I'm just starting to create my project but my simple test is given me errors.

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>

int main(int argc, const char * argv[]);
int a;//current #
int b;//computer move
int c;//human move
int d;//random move
int e;//test integer
int i;//turn counter

cin>> e; //expected unqualified-id //unknown type name 'cin'
cout<<(2*e); //expected unqualified-id //unknown type name 'cout'

Help!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <cstdio> // use the C++ headers, not the C headers
#include <cstdlib> // ditto
#include <iostream>
#include <cmath> // ditto

int main(int argc, const char * argv[])  // <- no semicolon.  This is not a prototype
{  // <- function body must go in braces.
    int currentNumber;  // <- give your variables meaningful names instead of single letters
    int computerMove;   // that way you don't need to comment what they are because
    int humanMove;      // the name tells you what they are.
    int randomMove;     // it makes your code much easier to read and understand
    int test;
    int turnCounter;

    std::cin >> test;      // cin is in the std namespace.  Full name is "std::cin"
    std::cout << (2*test); //ditto for cout
}  // <- end of function body requires closing brace 




If you do not want to type std::cin and std::cout... you can instead put using namespace std; in your code. This will take everything in the std namespace and dump it into the global namespace:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;  // <- dump the entire std namespace into the global namespace

int main(int argc, const char * argv[])
{
    //...
    cin >> test;  // now this will work
    cout << (2*test);
}
Last edited on
Thanks so much!
Topic archived. No new replies allowed.