Class Not Recognizing <iostream>

Hi, I'm a begginer programmer and am writing a practice program to play around with classes and header files and such. When I get this working I want to try adding pointers and such to start practicing that stuff.

For now, I am confused on why my "arrange" class functions are not recognizing the <iostream> header. When I try to compile this I get the following errors.

Error 1 error C2065: 'cout' : undeclared identifier
Error 2 error C2065: 'endl' : undeclared identifier

Here's my source:
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
//pointerpractics.cpp
#include <iostream>
#include "arrange.h"

arrange::arrange(void)
{
}

arrange::~arrange(void)
{
}

void arrange::backward(char name[20])
{
	char bname[20];

	for(int i = 0 ; i < 20 ; i++)
	{
		int j = 19;
		bname[i] = name[j];
		j--;
	}

	cout << bname << endl;
}
char arrange::down(char *name)
{
	return 0;
}
char arrange::up(char *name)
{
	return 0;
}


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
//arrange.cpp
#include <iostream>
#include "arrange.h"

arrange::arrange(void)
{
}

arrange::~arrange(void)
{
}

void arrange::backward(char name[20])
{
	char bname[20];

	for(int i = 0 ; i < 20 ; i++)
	{
		int j = 19;
		bname[i] = name[j];
		j--;
	}

	cout << bname << endl;
}


1
2
3
4
5
6
7
8
9
10
//arrange.h
#pragma once

class arrange
{
public:
	arrange(void);
	~arrange(void);
	void backward(char name[20]);
};

Well the problem you're asking about is caused by you not being in std namespace (I can't believe how often this question gets asked here!)

Either do std::cout and std::endl, or put using namespace std; in functions which use them, or at the top of your cpp file if several functions use them.

Another problem here is that you're giving the same functions multiple bodies, which will cause linking errors (the linker won't know which function to use). Functions can only have 1 body.

You also have 'up' and 'down' functions in pointerpractics.cpp, but those functions aren't part of the arrange class (not in arrange.h)
>< I can't believe I missed that. Also, I think linked the wrong code for pointerpractice.cpp which is why I had extra stuff there.

Thanks for the reply.
Topic archived. No new replies allowed.