1>c:\documents and settings\joe\desktop\spring 2010\csc 212\hw\hw #5\rec_fun_test.cpp(25) : error C2065: 'outs' : undeclared identifier

i keep getting this from one of my codes

it is from a prototype
void binary_print(ostream& outs, unsigned int n);

is there a #include needed for that or something????

please help!!!

Recommended Answers

All 5 Replies

We really need to see a bit more of the code - show the line the compiler error points to.

Do you have

#include <fstream>

in your file?

We really need to see a bit more of the code - show the line the compiler error points to.

Do you have

#include <fstream>

in your file?

im calling this function from main

bin_p.binary_print(outs, n);
^that is in int main()

void binary_print(ostream& outs, unsigned int n);
^this is in the header file

void rec_fun::binary_print(ostream& outs, unsigned int n)
{
if(n < 2)
{
cout << n << endl;
}
else if(n >= 2)
{
binary_print(outs, n/2);
cout << (n%2);
}
}
^implementation file

all 3 files have #include<iostream>,<cstdlib>,using namespace std

hope thats enough info for u to help me!! please :)

im calling this function from main

bin_p.binary_print(outs, n);
^that is in int main()

void binary_print(ostream& outs, unsigned int n);
^this is in the header file

void rec_fun::binary_print(ostream& outs, unsigned int n)
	{
		if(n < 2)
		{
			cout << n << endl;
		}
		else if(n >= 2)
		{
			binary_print(outs, n/2);
			cout << (n%2);
		}
	}

^implementation file

all 3 files have #include<iostream>,<cstdlib>,using namespace std

hope thats enough info for u to help me!! please :)

What the error is telling you is that it doesn't know what outs is.

Before you call bin_p.binary_print(outs, n); you must have declared outs:
something along these lines: ostream outs; this is the most likely place where you have made an error perhaps a typo in variable name.

Another question:

your method does not use the variable <icode>outs</icode> so what is its purpose?


Occasionally you can have problems using references of fstreams but I don't think that this is an issue here.

In main(), do you declare ostream outs; ?

And just for your info, you don't need to test the >= condition. When the first if test fails, all you need is an else, the value must be >= 2 to get there.

all 3 files have #include<iostream>,<cstdlib>,using namespace std

and #include <fstream> ?????

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.