 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ron Natalie Guest
|
Posted: Thu Feb 10, 2005 11:21 am Post subject: Re: Error reading files in ios::binary mode |
|
|
WahJava wrote:
| Quote: | Hi developers,
I'm running GCC (GNU C/C++ Compiler shipped with Fedora Core 2). I've
written a program using IOStream classes, in which I'm reading files in
ios::binary mode.
|
You don't show us the open.
I assume you've determined that sizeof(int) is what you expect.
What does is the state of the stream before the read, after the read?
What characters do you expect, what did you observe.
IT ALSWAYS BEHOOVES YOU WHEN ASKING FOR FREE ADVICE TO:
1. Provide a complete example of the problem.
2. Indicate what you thought should happen.
3. Indicate what you observed happening.
|
|
| Back to top |
|
 |
WahJava Guest
|
Posted: Thu Feb 10, 2005 11:58 am Post subject: Error reading files in ios::binary mode |
|
|
Hi developers,
I'm running GCC (GNU C/C++ Compiler shipped with Fedora Core 2). I've
written a program using IOStream classes, in which I'm reading files in
ios::binary mode. I'm using read() method (exact signature not
remembered) of the std::istream class ? When I'm reading the value in
objects attribute (member variable), the read fails, but when I'm
reading in a local variable value is successfully read as shown below:
..... any includes that are necessary
class a {
int magik;
public:
void go(ifstream&);
};
void a::go(ifstream& in) {
int j;
in.read((char*)&magik, sizeof(int)); // Incorrect value read in
magik
}
/*
* If instead of address of a::magik above if I'll pass the local var.
j
* the code works fine.
*/
The above code works fine on Microsoft C/C++ compiler shipped with
Microsoft Visual C++ Toolkit 2003 but fails with MingW GCC 3.4 (same
problem).
Any suggestions,
Thanks,
Ashish Shukla alias Wah Java !!
Wah Java !!
|
|
| Back to top |
|
 |
WahJava Guest
|
Posted: Wed Mar 02, 2005 12:11 pm Post subject: Re: Error reading files in ios::binary mode |
|
|
Hi Ron,
Sorry 4 being late. Right now I don't have the code to demonstrate
this. But the objective is I want to read an integer (4 bytes) from a
file opened in binary mode.
But when I'm reading value in local variable code works fine, variable
is read successfully but when reading into class member variable, read
is unsuccessful, the value in the variable, is unpredictable.
The same program works fine with MS Visual C++ Toolkit 2003, but fails
with GCC.
Thanx,
Ashish Shukla alias Wah Java !!
Wah Java !!
Ron Natalie wrote:
| Quote: | WahJava wrote:
Hi developers,
I'm running GCC (GNU C/C++ Compiler shipped with Fedora Core 2).
I've
written a program using IOStream classes, in which I'm reading
files in
ios::binary mode.
You don't show us the open.
I assume you've determined that sizeof(int) is what you expect.
What does is the state of the stream before the read, after the read?
What characters do you expect, what did you observe.
IT ALSWAYS BEHOOVES YOU WHEN ASKING FOR FREE ADVICE TO:
1. Provide a complete example of the problem.
2. Indicate what you thought should happen.
3. Indicate what you observed happening.
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|