Visual Studio Development Bookmark and Share   
 index > Visual C++ Express Edition > fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory
 

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

Hie,

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.

gintoki  Wednesday, April 23, 2008 5:02 PM

Quote>As far as I'm concerned I don't think anything is wrong with the coding.

Do you feel you're experienced enough already to judge?

Code Snippet

#include <iostream>

is correct. The errors you got with that were due to the fact that
iostreams are in the std namespace. There are at least three ways
to amend your program to make it compile. Choose ONE of these:

(1) Put this statement immediately after the #include:

Code Snippet

using namespace std;

(2) Put these statements immediately after the #include:

Code Snippet

using std::cout;
using std::cin;
using std::endl;

(3) Change your code to this:

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

While (1) is the easiest, it is generally discouraged as it defeats
the purpose of namespaces.

Note also that you should have
int main()
as that is what the C++ Standard specifies.

- Wayne

  • Edited byWayneAKing Saturday, December 13, 2008 10:20 PMFix typos
  •  
WayneAKing  Wednesday, April 23, 2008 7:38 PM

Quote>As far as I'm concerned I don't think anything is wrong with the coding.

Do you feel you're experienced enough already to judge?

Code Snippet

#include <iostream>

is correct. The errors you got with that were due to the fact that
iostreams are in the std namespace. There are at least three ways
to amend your program to make it compile. Choose ONE of these:

(1) Put this statement immediately after the #include:

Code Snippet

using namespace std;

(2) Put these statements immediately after the #include:

Code Snippet

using std::cout;
using std::cin;
using std::endl;

(3) Change your code to this:

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

While (1) is the easiest, it is generally discouraged as it defeats
the purpose of namespaces.

Note also that you should have
int main()
as that is what the C++ Standard specifies.

- Wayne

  • Edited byWayneAKing Saturday, December 13, 2008 10:20 PMFix typos
  •  
WayneAKing  Wednesday, April 23, 2008 7:38 PM

Quote> Do you feel you're experienced enough already to judge?

Lol i'm only new in visual c++ but still i know the basics. Just for that simple code i thinkconfident enuf to say"i got experience". Anyway was joking,okay back to business. I've tried the using namespace std part and i got it correct before u replied.but i'm not too sure about the functions. The reply u gave took out most of the questions i want to ask. I really appreciate it. Thanks.

Apart from that, I'd like to ask about the usage of the code :

Code Snippet

using namepace std;

Still not very clear about it. To me it's kind of like a declaration for the cint and cout thing but i guess it's not that general right. Another thing that concerns me is the second and the third solution provided by you. Since u provide me with 3 solutions and you said no 1 is not really recommended which one do you think is more relevant and should be taken note as a programmer. Since those 3 are almost the same, which means they are only different ways of declaration, i don't think it really matters which statement we choose (correct me if i'm wrong).
As for the part which i used void main(), I actually just copied it directly from the book. I'm not sure what int main does. But if i'm not mistaken, when u use void the end product doesn't return a value and when u use int you can call for a return value.
Once again, thanks for replying Wayne. The information you gave was really helpful. Nice reading ur reply. Have a nice day.
-Gintoki-
gintoki  Thursday, April 24, 2008 3:12 AM

Solution (1) is not recommended as it puts everything in the std namespace.

This can lead to name conflicts.

Solution (2) is better as it limits what is implicitly in the std namespace.

There is still a reduced risk of conflicts. For example, if someone were

to useendl in their own code it could be mistaken by the compiler for

std::endl in iostreams. (Or vice versa.)

Solution (3) is best as it specifies the namespace each time the

iostream members are used. There is no chance that a mismatch

will occur with like-named items.

The main() function must return an int, if it is to conform to the ANSI/ISO

C++ Language Standard. (And the C Standard.) Any other function may

be defined to return void, if desired.

- Wayne

WayneAKing  Thursday, April 24, 2008 3:47 AM

Thanks.I go try it out now.Are u using msn messenger? I was thinking of adding u into my buddy list.

gintoki  Thursday, April 24, 2008 3:55 AM

Quote>Are u using msn messenger?

Nope.

- Wayne

WayneAKing  Thursday, April 24, 2008 1:07 PM

You can use google to search for other answers

Custom Search

More Threads

• Listcontrol in MFC
• Delegate Error
• How to convert char string to Unicode?
• Certification Help
• C++ Express winodws 32 applications Problems ??
• C++ Win32 ReadFile()
• Math.Sqrt Problem
• How do I create DLL
• help please runtime error
• Draw/clear shapes in VC++?