Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,766 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,145 people online right now. Registration is fast and FREE... Join Now!




'cout' Undeclared (first Use This Function)

3 Pages V  1 2 3 >  
Reply to this topicStart new topic

'cout' Undeclared (first Use This Function)

DivineFlux
post 6 Jan, 2005 - 10:33 AM
Post #1


New D.I.C Head

*
Joined: 6 Jan, 2005
Posts: 5

Ok, so I'm really confused here. huh.gif I got "C++ for Dummies" for Christmas and was starting to work through the book. Did the first coding exercise (which was basicly just to see how a simple program looked) but that is as far as I've gotten.

I keep getting these errors that say
CODE
'cout' undeclared (first use this function)
and
CODE
'cin' undeclared (first use this function)
but the coding is written exactly as in the example. I even tried it with the pre-made file and still get the same error.

Here is the code from the pre-made example file:

CODE

//
//  Conversion - convert temperature from Celsius
//           degree units into Fahrenheit degree
//               units:
//      Fahrenheit = Celsius  * (212 - 32)/100 + 32
//
#include <stdio.h>
#include <iostream.h>
int main(int nNumberofArgs, char* pszArgs[])
{
   // enter the temperature in Celsius
   int nCelsius;
   cout << "Enter the temperature in Celsius:";
   cin  >> nCelsius;

   // calculate conversion factor for Celsius
   // to Fahrenheit
   int nFactor;
   nFactor = 212 - 32;

   // use conversion factor to convert Celsius
   // into Fahrenheit values
   int nFahrenheit;
   nFahrenheit = nFactor * nCelsius/100 + 32;

   // output the results
   cout << "Fahrenheit value is:";
   cout << nFahrenheit;

   return 0;
}


The two errors that I get are:

Error: error: 'cout' undeclared (first use this function)
Error: error: 'cin' undeclared (first use this function)


I'm using the latest software from DJGPP (which is the updated version of what comes with the book) for Win2K.

I am hoping that I'll have less problems with all of this once I get Visual Studio.NET running on my 'puter.

Thanks for all your help.
User is offlineProfile CardPM

Go to the top of the page

supersloth
post 6 Jan, 2005 - 10:54 AM
Post #2


serial frotteur

Group Icon
Joined: 21 Mar, 2001
Posts: 19,501



Thanked 11 times

Dream Kudos: 2147483647

Expert In: being gentlemanly

My Contributions


does a simple hello world compile?

CODE

#include <iostream.h>
void main()
{
  cout << "Hello World";
}


???

and (i know this is a long shot) your compiler support the .h header files? i.e. if you use iostream instead of iostream.h does the error change?
User is online!Profile CardPM

Go to the top of the page

Nova Dragoon
post 6 Jan, 2005 - 11:01 AM
Post #3


The Innocent Shall Suffer, Big Time

Group Icon
Joined: 16 Aug, 2001
Posts: 6,128



Thanked 4 times

Dream Kudos: 515

Expert In: Python, Linux

My Contributions


use #include <iostream> not iostream.h

after all the includes

add this line

using namespace std;
User is online!Profile CardPM

Go to the top of the page

supersloth
post 6 Jan, 2005 - 11:06 AM
Post #4


serial frotteur

Group Icon
Joined: 21 Mar, 2001
Posts: 19,501



Thanked 11 times

Dream Kudos: 2147483647

Expert In: being gentlemanly

My Contributions


yeah, thats what i was going for in the second part of my response.
User is online!Profile CardPM

Go to the top of the page

DivineFlux
post 6 Jan, 2005 - 11:44 AM
Post #5


New D.I.C Head

*
Joined: 6 Jan, 2005
Posts: 5

QUOTE
does a simple hello world compile?

CODE

#include <iostream.h>
void main()
{
  cout << "Hello World";
}


Nope, I get these errors:

Error: error: 'main' must return 'int'
In function 'int main(...)':
Error: error: 'cout' undeclared (first use this function)

QUOTE
and (i know this is a long shot) your compiler support the .h header files? i.e. if you use iostream instead of iostream.h does the error change?


It doesn't appear to matter if I have the .h or not. I get the same error messages either way.
User is offlineProfile CardPM

Go to the top of the page

DivineFlux
post 6 Jan, 2005 - 11:46 AM
Post #6


New D.I.C Head

*
Joined: 6 Jan, 2005
Posts: 5

QUOTE
use #include <iostream>  not iostream.h

after all the includes

add this line

using namespace std;


Did both, but still no change.
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 6 Jan, 2005 - 12:33 PM
Post #7


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,165



Thanked 32 times

Dream Kudos: 25
My Contributions


[QUOTE=DivineFlux,Jan 6 2005, 02:44 PM]
CODE

#include <iostream.h>
void main()
{
  cout << "Hello World";
}
[/QUOTE]

Nope, I get these errors:

Error: error: 'main' must return 'int'
In function 'int main(...)':
Error: error: 'cout' undeclared (first use this function)

[/QUOTE]
The main function shown there does not require an int return, it has a void return. If you're getting that error, then you're not compiling that main function, but another.

As for the headers, sometimes DJGPP needs to have compile time librairies downloaded and installed separately, although they should have been included on the CD. Here is part of the FAQ.

You also might want to try it with all the comments removed. Some versions of DJGPP do not support the // comments.

You might also want to make sure that the compiler is recognizing the correct source language.

The code you originally posted will definitely run in Visual Studio.
User is online!Profile CardPM

Go to the top of the page

Amadeus
post 6 Jan, 2005 - 12:39 PM
Post #8


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,165



Thanked 32 times

Dream Kudos: 25
My Contributions


What command are you using to compile? I haven't used DJGPP in quite some time, but it used to be that gcc was the c compiler, and gxx was the c++ compiler. this may well have changed.
User is online!Profile CardPM

Go to the top of the page

DivineFlux
post 6 Jan, 2005 - 12:49 PM
Post #9


New D.I.C Head

*
Joined: 6 Jan, 2005
Posts: 5

QUOTE
The main function shown there does not require an int return, it has a void return. If you're getting that error, then you're not compiling that main function, but another.


I must be missing something then that is suppose to be in my program. How else could it be compiling the wrong function. Unless there are some bugs in the copy of DJGPP I got. But I probably just missed downloading and installing something.

QUOTE
As for the headers, sometimes DJGPP needs to have compile time librairies downloaded and installed separately, although they should have been included on the CD. Here is part of the FAQ.


Unfortunately, I got it all from their website. The program that came with the book is from before 2000. And their site said that I needed to download the version that came out in 2002 (or was it 2003) because the original program had a lot of problems running on Win2K and WinXP. But the site isn't all that user friendly for people who don't know what all they are going to need. What ever happened to lumping everything into one easy (but long) download? Argh... hehee

QUOTE
The code you originally posted will definitely run in Visual Studio.


This is a relief. Visual Studio.NET is one of the required programs for my program of study. And damn if it isn't a huge program. I thought it would be an easy install, but boy if I wasn't wrong. Hell, just all the CDs I have to use to install it all....and then there are the 4 MDNS (or whatever the letters are) library disks that go with it...it is like a grand total of 8 CDs. Time to save up for that new harddrive.

QUOTE
You might also want to make sure that the compiler is recognizing the correct source language.


How would I go about doing this?
User is offlineProfile CardPM

Go to the top of the page

DivineFlux
post 6 Jan, 2005 - 01:08 PM
Post #10


New D.I.C Head

*
Joined: 6 Jan, 2005
Posts: 5

QUOTE
What command are you using to compile? I haven't used DJGPP in quite some time, but it used to be that gcc was the c compiler, and gxx was the c++ compiler. this may well have changed.


I'm guessing that they changed gxx to gpp.

This is what it said to download and install:

unzip32.exe to unzip the zip files

v2/copying.dj DJGPP Copyright info
v2/djdev203.zip DJGPP Basic Development Kit
v2/faq230b.zip Frequently Asked Questions
v2/pakk023b.zip Pakke Installer
v2/readme.1st Installation instructions

v2apps/rhide15b.zip RHIDE

v2gnu/bnu215b.zip Basic assembler, linker
v2gnu/fil41b.zip File Utils (for building Allegro)
v2gnu/gcc343b.zip Basic GCC compiler
v2gnu/gpp343b.zip C++ compiler
v2gnu/mak3791b.zip Make (processes makefiles)
v2gnu/txi47b.zip Info file viewer

v2tk/allegro/all403.zip Allegro game library

v2tk/grx246s.zip GRX Graphics
v2tk/pdcur24b.zip Curses Emulator
v2tk/rsxdj151.zip RSX (Windows GUI Lib)
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 6 Jan, 2005 - 05:32 PM
Post #11


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,165



Thanked 32 times

Dream Kudos: 25
My Contributions


Is this the ouput from your initial install? You can also try to force namespace recognition by using the following nomenclature
CODE

std::cout

You should not have to do this because you've declared that you're using namespace std, but it's worth a shot.

I assume you've posted the code exactly as you're trying to compile? Can you post the exact command line command you're using to compile the file?
User is online!Profile CardPM

Go to the top of the page

ands122
post 19 Jun, 2005 - 07:24 AM
Post #12


New D.I.C Head

*
Joined: 19 Jun, 2005
Posts: 1

cout undeclared


1. Example

xyz.cpp: In function `int main()':
xyz.cpp:6: `cout' undeclared (first use this function)
xyz.cpp:6: (Each undeclared identifier is reported only once for each
function it appears in.)

2. Meaning
This is really a special case of "undeclared identifier".
Usual causes
a. You forgot to include <ostream>
b. You forgot "using namespace std;"
User is offlineProfile CardPM

Go to the top of the page

3 Pages V  1 2 3 >
Reply to this topicStart new topic
Time is now: 11/20/08 01:14PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month