# 'cout' Undeclared (first Use This Function)

• (2 Pages)
• 1
• 2

## 28 Replies - 51444 Views - Last Post: 04 November 2009 - 11:52 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=9988&amp;s=c01f8fa66cc7126489b4b9a1915762d9&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 DivineFlux

• New D.I.C Head

Reputation: 0
• Posts: 5
• Joined: 06-January 05

# 'cout' Undeclared (first Use This Function)

Posted 06 January 2005 - 11:33 AM

Ok, so I'm really confused here. 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
```'cout' undeclared (first use this function)
```
and
```'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:

```//
//  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.

Is This A Good Question/Topic? 0

### #3 supersloth

• serial frotteur - RUDEST MEMBER ON D.I.C.

Reputation: 4558
• Posts: 28,442
• Joined: 21-March 01

## Re: 'cout' Undeclared (first Use This Function)

Posted 06 January 2005 - 11:54 AM

does a simple hello world compile?

```#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?

### #12 Nova Dragoon

• The Innocent Shall Suffer, Big Time

Reputation: 36
• Posts: 6,169
• Joined: 16-August 01

## Re: 'cout' Undeclared (first Use This Function)

Posted 06 January 2005 - 12:01 PM

use #include <iostream> not iostream.h

after all the includes

using namespace std;

### #13 supersloth

• serial frotteur - RUDEST MEMBER ON D.I.C.

Reputation: 4558
• Posts: 28,442
• Joined: 21-March 01

## Re: 'cout' Undeclared (first Use This Function)

Posted 06 January 2005 - 12:06 PM

yeah, thats what i was going for in the second part of my response.

### #14 DivineFlux

• New D.I.C Head

Reputation: 0
• Posts: 5
• Joined: 06-January 05

## Re: 'cout' Undeclared (first Use This Function)

Posted 06 January 2005 - 12:44 PM

Quote

does a simple hello world compile?

```#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.

### #15 DivineFlux

• New D.I.C Head

Reputation: 0
• Posts: 5
• Joined: 06-January 05

## Re: 'cout' Undeclared (first Use This Function)

Posted 06 January 2005 - 12:46 PM

Quote

use #include <iostream>  not iostream.h

after all the includes

using namespace std;

Did both, but still no change.

• g+ + -o drink whiskey.cpp

Reputation: 248
• Posts: 13,507
• Joined: 12-July 02

## Re: 'cout' Undeclared (first Use This Function)

Posted 06 January 2005 - 01:33 PM

DivineFlux, on Jan 6 2005, 02:44 PM, said:

```#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]
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.

• g+ + -o drink whiskey.cpp

Reputation: 248
• Posts: 13,507
• Joined: 12-July 02

## Re: 'cout' Undeclared (first Use This Function)

Posted 06 January 2005 - 01:39 PM

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.

### #18 DivineFlux

• New D.I.C Head

Reputation: 0
• Posts: 5
• Joined: 06-January 05

## Re: 'cout' Undeclared (first Use This Function)

Posted 06 January 2005 - 01:49 PM

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?

### #19 DivineFlux

• New D.I.C Head

Reputation: 0
• Posts: 5
• Joined: 06-January 05

## Re: 'cout' Undeclared (first Use This Function)

Posted 06 January 2005 - 02:08 PM

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

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)

• g+ + -o drink whiskey.cpp

Reputation: 248
• Posts: 13,507
• Joined: 12-July 02

## Re: 'cout' Undeclared (first Use This Function)

Posted 06 January 2005 - 06:32 PM

Is this the ouput from your initial install? You can also try to force namespace recognition by using the following nomenclature
```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?

### #21 ands122

• New D.I.C Head

Reputation: 0
• Posts: 1
• Joined: 19-June 05

## Re: 'cout' Undeclared (first Use This Function)

Posted 19 June 2005 - 08:24 AM

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;"

• g+ + -o drink whiskey.cpp

Reputation: 248
• Posts: 13,507
• Joined: 12-July 02

## Re: 'cout' Undeclared (first Use This Function)

Posted 19 June 2005 - 09:21 AM

True, but <ostream> is a subset of <iostream>, which was included by the user, and some of the older compilers do not support the deprecation of the .h libraries.

### #23 Sargant

Reputation: 0
• Posts: 91
• Joined: 30-November 01

## Re: 'cout' Undeclared (first Use This Function)

Posted 18 July 2005 - 01:42 PM

My Â£0.02 as an absolute newbie: I was getting this exact same pair of errors with <iostream.h> and <iostream> using Dev-C++. Turns out I had set the project properties to Win32 GUI - setting it to Win32 Console fixed it.

### #24 PaiN KilleR

• New D.I.C Head

Reputation: 0
• Posts: 5
• Joined: 01-September 07

## Re: 'cout' Undeclared (first Use This Function)

Posted 01 September 2007 - 08:37 PM

```#include <ostream>
using namespace std;

float QProf1, QProf2, QProf3, QProf4, QProf5, QProf6, QProf7, QProf8, QProf9, QProf10, QProf11, QProf12
, QProf13, QProf14, QProf15, QProf16, QProf17, QProf18, QProf19, QProf20, QProf21, QProf22, QProf23, QProf24
, QProf25, QProf26, QProf27, QProf28, MoyAProf, MoyBProf, MoyCProf;
int main ()
{

cout>>"Vous pourrez ici entrez le score (0 à 3) du Client/Patient pour les questions de 1 à 28 inclusivement.";

cout<<"Question numéro 1";
cin>>QProf1;
// (i copied first one and past it 27 times
// to get to Qprof28 variable) I cut off some
// of it cuz it's kinda long and all the same through :
cout<<"Question numéro 28";
cin>>QProf28;

MoyAProf= (QProf4 + QProf5 + QProf6 + QProf10 + QProf11 + QProf12 + QProf23 + QProf27) / 8.0;
MoyBProf= (QProf1 + QProf2 + QProf3 + QProf8 + QProf14 + QProf15 + QProf16) / 7.0;
MoyCProf= (QProf7 + QProf9 + QProf18 + QProf20 + QProf21 + QProf22 + QProf26 + QProf28) / 8.0;

}
```

errors are:

error C2065: 'cout' : undeclared identifier
error C2065: 'cin' : undeclared identifier
warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
warning C4244: '=' : conversion from 'double' to 'float', possible loss of data

I was wondering why i get the Undeclared identifier for cin and cout (i've never got it O.O)

My Code is also not complete I wasn't done when i saw that error and now it's done and it's still doing the error
just so u know things btw " " are in french don'T botter with it

This post has been edited by PaiN KilleR: 01 September 2007 - 08:58 PM