Passing istream to a function

G

GameFreak7744

Hey, I'm trying to pass an open stream to a function so that data can
be read from it, so I that I don't have to keep opening and closing
streams all the time.

Anyway, the function definition is roughly this:

bool xCheckByteCode(istream & fsXSprite)


When I try to compile this, however, I get the following error message:

`istream' was not declared in this scope


What am I doing wrong here?

Cheers,
~Joey~
 
J

Jim Langston

GameFreak7744 said:
Hey, I'm trying to pass an open stream to a function so that data can
be read from it, so I that I don't have to keep opening and closing
streams all the time.

Anyway, the function definition is roughly this:

bool xCheckByteCode(istream & fsXSprite)


When I try to compile this, however, I get the following error message:

`istream' was not declared in this scope


What am I doing wrong here?

Cheers,
~Joey~

std::istream& ?
 
D

DragonSt0rm

Joey said:
Unfortunately no, when I tried that it informed me that " `istream' is
not a member of `std' ".

#include <iostream>
using namespace std;

before your function
 
J

Joey Sabey

DragonSt0rm said:
#include <iostream>
using namespace std;

before your function

That is included in the main file of my project, the one that then
includes the file containing this function.
Adding it to this file, also, causes this error: ' multiple definition
of `xCheckByteCode(std::istream&)' '

~Joey~
 
D

DragonSt0rm

Joey said:
That is included in the main file of my project, the one that then
includes the file containing this function.
Adding it to this file, also, causes this error: ' multiple definition
of `xCheckByteCode(std::istream&)' '


So you have an main.h where you do:

#include <iostream>
bool xCheckByteCode(std::istream & fsXSprite);

and then a main.cpp: with

#include "main.h"
using namespace std;

bool xCheckByteCode(std::istream & fsXSprite){
.............
}

Right ?
 
J

Joey Sabey

DragonSt0rm said:
So you have an main.h where you do:

#include <iostream>
bool xCheckByteCode(std::istream & fsXSprite);

and then a main.cpp: with

#include "main.h"
using namespace std;

bool xCheckByteCode(std::istream & fsXSprite){
............
}

Right ?

Not quite, as I have the #include in the .cpp, not the .h, etc. But I
have it working now.

Thanks for your time.
~Joey~
 
K

Kai-Uwe Bux

Joey said:
Unfortunately no, when I tried that it informed me that " `istream' is
not a member of `std' ".

Did you do

#include <istream>

or

#include <iostream>


Best

Kai-Uwe Bux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top