Hi all,
I used to write stuff in C++ on Linux, that did not cause any problems.
But suddenly I cannot do any file I/O with the C++ stream classes, I
think I did not change anything, what causes the trouble.
This seems to happen with every method, that accesses an opened
file like ifstream::seekp(), ifstream::getline(), ifstream::getc()
and so on. The following prog is just an example.
Does anybody know, what is wrong?
Cu Siggi
____________ the prog _____________________________________
#include<iostream.h>
#include<fstream.h>
void main(int argc, char **argv)
{
if(argv[1]) {
ifstream eingabeDatei(argv[1]);
if(!eingabeDatei) {
cerr << "File pointer is NULL!" << endl;
exit(1);
}
char testString[128];
// This line causes the seg fault
eingabeDatei.getline(testString, 127, '\n');
//^^^^^^^
cout << testString << endl;
} else {
cerr << "No filename" << endl;
}
___________________________________________________________Quote:} // end of main(...)
The file really exists, what is strange is, that the ifstream
constructor returns some value, but as soon as I do any
operation on that object I get a seg fault ?! 8-(
______ the gdb output _____________________________________
(gdb) run test.txt
Starting program: /home/spohl/C/test1 test.txt
test.txt
Program received signal SIGSEGV, Segmentation fault.
0x400a32e0 in _IO_getline (fp=???, buf=???, n=???, delim=???,
extract_delim=???)
Current language: auto; currently c
__________________________________________________________
__________ the s trace output (I left out the beginning)____
open("test.txt", O_RDONLY) = 3
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(4, 196), ...}) = 0
mmap(0, 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40008000
ioctl(1, TCGETS, {B9600 opost isig icanon echo ...}) = 0
write(1, "test.txt\n", 9test.txt
) = 9
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++
___________________________________________________________
_________ my configuration _____________________________
Linux Kernel 2.0.29
Gnu C++ 2.7.2.1
Binutils 2.8.1.0.1
C Library 5.4.33
ld.so 2.0.4
C++ Library 27.2.1
Pentium 200, 32 Megs (the usual stuff)
_____________________________________________________
--
=====================================================================
Siegfried Pohl
http://www.in-berlin.de/User/czbbs