I'm totally new to programming, but have been getting by fine so far.

I'm taking a highschool programming class, and am trying to do some of my assignments from home.

We've been told to work with <iostream.h> for our input and output, but for some reason, I get an error when I try to compile my programs at home;

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

The thing is, my code builds without errors when I'm working at school!

I've tried moving the libraries around so that Visual C++ can locate it, but nothing has worked so far.

I really want to start working with <stdio.h> and printf() but I don't think my teacher would accept the work, since he's hellbent on getting us to code with older techniques. (Seems like the lines we're writing aren't very "hip" anymore, since everywhere I look outputs are accomplished with printf() and such.)

Sorry if it was a stupid question. I'll try fiddling some more while I wait for responses. :)

Recommended Answers

All 4 Replies

<iostream.h> is a deprecated header, and was never part of standard C++. I'm assuming you're using VC++6.0 or a similarly older version of Borland. The standard header is <iostream> so you may have to change it between school and home. You may consider raising the issue with your teacher, but there's a chance that he doesn't care, or may even get mad at you.

I really want to start working with <stdio.h> and printf() but I don't think my teacher would accept the work, since he's hellbent on getting us to code with older techniques. (Seems like the lines we're writing aren't very "hip" anymore, since everywhere I look outputs are accomplished with printf() and such.)

printf() is the C way of managing output, and it's much older than C++ output using cout. ;)

> We've been told to work with <iostream.h> for our input and output

Your compiler probably doesn't support it because that header is old and outdated. Try using the Standard Template Library; it's up-to-date and you'll notice the headers don't have a file extension:

#include <iostream>
using namespace std;

> I really want to start working with <stdio.h> and printf()
You're confusing C and C++. stdio.h and printf() are actually C functions. For now, stick with the C++ and the standard template library.

> but I don't think my teacher would accept the work
There is nothing incorrect about using modern coding methods, nor is there any reason why you should revert to outdated libraries. The snippet I showed you above is correct; using iostream.h is not. If he disapproves of it, show him this link.

> since everywhere I look outputs are accomplished with printf() and such.
Actually C++ was invented after C, so printf() and scanf() are actually older than cin and cout. Both languages have their advantages and disadvantages, and although you can mix them, it's generally not a good idea unless you know what you're doing.

Thanks much! I did try using <iostream>, but now I'm getting errors on lines when I use cout, cin and endl; statements. Hah!

EDIT: Thanks joeprogrammer. Your snippet has my program working! I'll be sure to pass on that link to my teacher. Whether or not he'll take to it, I'm not sure. He admitted to not programming in C++ for several years now, and being comfortable with older languages like FORTRAN.

I'm guessing the textbook (published in 1997 ... ) isn't really up to date with the standards of Vis 2005.

Thanks for the help. I'll just have to fiddle with my code in order for it to make the jump from school to home. There's a translation that needs to occur, I just need to find out how to do it. I just hope the work I'm doing now will be useful to my studies in University next year, especially if we're working with a decade-old text!

be sure to use the correct namespace when addresses those methods.
They're in the std namespace (and have been for the last 10 years or so, so since just after your book was published).

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.