compiler error of undeclared cin & l.. I need assistance

I have been learning how to add multi files using headers, but VS express 2015 gives me an error of cin and l not declared in the main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68


#include<iostream>

#include"add.h"
#include"subtract.h"
#include"math.h"




/*separate file (add.cpp)
int add(int a, int b) {
	return a + b;

}
*/

/*separate file (add.h)

#pragma once
int add(int a, int b);
*/


/*separate file (subtract.cpp)
int subtract(int x, int y)
{
	return x - y;
}
*/


/*separate file (subtract.h)
#pragma once

int subtract(int x, int y);
*/

/* separate file (math.cpp)

int math(int l) 
{
	cin >> l;
	return 2 * l;
	
}
*/

/* separate file (math.h)
#pragma once
int math(int l);
*/



int main()
{
	using namespace std;
	cout << "8 + 3 = " << add(8, 3) << endl;
	
	cout << "5-3 = " << subtract(5, 3) << endl;

	cout << "2 * 2 = " << math(l) << endl;

	return 0;
	
}
Last edited on
line 40-47: math.cpp does not include <iostream> or have using namespace std.
Therefore at line 44, the compiler does not know what cin is.
@AbstractionAnon Ive added it but still gives me the same errors
error again.. is there something i am not doing right?


Error C2039 'cout': is not a member of 'std' ConsoleApplication3
Okay i got it to work by adding #include<iostream> .. :) much relieved now!! Wooh!
Topic archived. No new replies allowed.