View Full Version : HELP!!! Unable to use iostream.h using C, instead of C++

04-02-2004, 09:09 AM
Hi everyone, I tried to used iostream.h into my file so that I can open a file for OpenGL but it seems like it's not going work.

Can anyone help?

#include <gl/glut.h>
#include <gl/glu.h>
#include <iostream.h>
#include <fstream.h>

void InputImage(void)
printf("Enter the name of the input file : ");
/* try to open file for reading (r) in binary (b) mode */
if ((inf_handle = fopen(inf_name, "rb")) == NULL) /* open failed */
puts("*** Can't open input file - please check file name typed!\n ");
charin = getchar();
exit(1); /* terminate execution */

04-02-2004, 10:01 AM
You're trying to use iostream in C? In a .c file? Because that won't work. Iostream uses classes. C++ only.

04-02-2004, 10:18 AM
Ya, now I know. I NEED HELP!!!

For example, I startt the .exe file, the question prompt

"Enter the file name: - "

And I want to type the filename, how do I read or type in the file name?

04-02-2004, 11:01 AM
No offense but this:

a.) has not ANYTHING to do with OpenGL.
b.) Is VERY basic C/C++ knowledge.

I suggest you grab a beginners book to C/C++, its all in there.

04-02-2004, 11:38 AM
I know it got nothing to do with OpenGL,but I'm currently doing OpenGL and I need to know this "basic C and C++" code to continue with it! :(

04-02-2004, 11:51 AM
They are lots of websites with basic C/C++ information.

You can compile C code under C++, but not the other way around. You need to ether change to C++ (.cpp) or do all the file I/O in C format.

But as you do some of the example openGL tutors like from nehe.gamedev.net, you will pick up how to do more C/C++ programming as you do along.

If you have a non-openGL question about C/C++, just drop me an e-mail and will see if I can help you.

04-02-2004, 08:17 PM
Remember, you can't use STL, <iostream.h>, etc. in C. But, you may consider coding your OGL Apps in C++ unless you have some specific reason not to. OOP is pretty useful in games, but some people still swear by C. Ultimately it's up to you, but C++ is my preference.

04-05-2004, 09:20 AM
#include <stdio.h> instead, of iostream.h and fstream. You're trying to include the C++ headers for i/o, but using the C functions for i/o.

As has already been said, you should really get a better grasp of C/C++ before starting down the path of using OpenGL.