jump to navigation

Why can’t we use CIN or IOSTREAM.H? March 18, 2010

Posted by etschneider in programming.
Tags: , , , ,

We noticed while trying to type very (but very) simple examples of C++ programs with Visual Studio 2008/2005 (and here by Wikipedia), we obtained several error messages depending how far we managed to lead our investigations.

The first one was:

fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory

Yes, indeed it is a kind of insult: iostream.h does not exist! Hum. The first possible cause would be a bad installation, but that would be weird, since all the labs’PC would be concerned… Well, with a ghost that could be possible… Still more investigation and common sense were necessary…

Next step would be to change the <iostream.h> into <iostream>.

Well the result was different:

error C2065: 'cout' : undeclared identifier

OK, now cout is not recognized. Weird (2nd). Argh! (usually the lecturer is falling at that time, because he was used to other, more permissive compiler and didn’t know what to do).

So, there is no need to give up, we will continue the investigation further. Later on, with the help of L.U.C.K and Google, I started to have some first hints. Especially one leading to the Microsoft website. A little bit more time later, and using the internal search of the MSDN website I found this:


I’m a new Visual C++ programmer and I’m learning the coding by myself. The book which I’m refering to is based on Microsoft Visual C++ 2005 and the version which I’m using is Microsoft Visual C++ 2008.
Well I’m currently having problems with my coding. Well this is the sample which I’m working on

#include <iostream.h>

void main()
   double radius, area;
   cout << "\nEnter radius: " ;
   cin >> radius ;
   area = 3.14159 * radius * radius ;
   cout << "Area = "<< area ;

As far as I’m concerned I don’t think anything is wrong with the coding. First i tried

#include <iostream>
3 errors were found

1>.\wadever.cpp(8) : error C2065: 'cout' : undeclared identifier
1>.\wadever.cpp(9) : error C2065: 'cin' : undeclared identifier
1>.\wadever.cpp(11) : error C2065: 'cout' : undeclared identifier

When i changed it to the coding as written on the above, this came out.

1>.\wadever.cpp(1) : fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory

Thanks for reading, have a nice day.

For further reading have a look at the original post on the MSDN website.

So the answer lies in one word: standard (the ISO standard in fact for C++ which is supported by VS C++ 2005/2008(Express Edition)). One of the answer was:

(3) Change your code to this:

   std::cout << "\nEnter radius: " ;
   std::cin >> radius ;
   area = 3.14159 * radius * radius ;
   std::cout << "Area = "<< area ;

I put the changes in bold characters. In fact, from the C++ standard, we should indicate the namespace for some of the functions we use, in this case we are speaking about “STandarD”. If I don’t forget, I’ll come back on that subject later on. Until then, the problem is considered as solved (well, it was not really a problem).



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: