seg fault with IO
Gerald Gutierrez
gutier@intergate.bc.ca
Sat Nov 13 22:13:00 GMT 1999
> There's no indication of where the program faulted, i.e., was it
> the ifstream
> constructor, or was it the read() function?
Oh, I forgot to mention that, sorry. It seems to be with the read(),
though the debugger output really tells nothing useful (at least to
me).
Program received signal SIGSEGV, Segmentation fault.
0x804c49f in main (ac=1, av=0x7ffff974) at read.cc:11
11 return 0;
(gdb) where
#0 0x804c49f in main (ac=1, av=0x7ffff974) at read.cc:11
> I assume you know that ifs.get(ch); would be an easier way to read in a
> single character, and that the code you posted is an extreme simplification
> of what you're actually trying to do. :-)
Yes it is. I'm sure it's the read statement because if I comment it
out, it compiles fine and the program runs to completion.
read(&ch,1) and get(ch) does the same thing, right? Can anyone else
reproduce this seg fault? Or is it just me ...
I'll report the source. Thanks for any help.
#include <fstream>
using namespace std;
int
main(int ac, char* av[])
{
ifstream ifs("read.cc");
char ch;
ifs.read(&ch, 1); // <-- Problem here
return 0;
}
More information about the Libstdc++
mailing list