I agree with matsp: ios::trunc | ios::app does not make sense. In The C++ Standard Library: A Tutorial and Reference Josuttis states on page 632 that "other combinations not listed in the table, such as trunc|app, not allowed".
I agree with matsp: ios::trunc | ios::app does not make sense. In The C++ Standard Library: A Tutorial and Reference Josuttis states on page 632 that "other combinations not listed in the table, such as trunc|app, not allowed".
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I tried to seperate them, like so, but it still didn't work (same segmentation fault).
Code:ofstream accfile; accfile.open ("loans.txt", ios::trunc); accfile.close(); accfile.open ("loans.txt", ios::app);
Yes, I said that - but I also said "Do not combine app with trunc" as you are at the same time saying "truncate the file" and "append to the file" - which makes absolutely no sense - and what you actually get from it is completely undefined.
What I wanted to tell is that IF you have valid combinations that you want to pass in, you need to combine them using the bitwise or operator.
Did you actually test if accfile is valid before writing to it? Such as
It may well be that the iostream implementation actually detects the bad combination and the opening of the file fails, perhaps?Code:if (!accFile) { cout << "Could not open the file... " << endl; return; }
I am also a bit suspicious about this one:
Why is there a +1 there?Code:for (int i = 0; i < (BOOK_MAX+1); i++)
--
Mats
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.