ofstream random access not working / developer error

L

Lars Uffmann

kwikius said:
AFAIK you can control some aspects of exception throwing in regard to
the state flags, via exceptions(flags) member function in basic_ios.
Thanks, that's all I needed to know, really:
/* ... */
indexFile.exceptions (ios_base::failbit);
try {
indexFile.open (filename, ios_base::binary | ios_base::in | ios_base::eek:ut);
}
catch (exception &e) {
cout << "file not open" << endl;
}
if (!indexFile.is_open()) {
cout << "creating index file" << endl;
indexFile.clear();
indexFile.open (filename, ios_base::binary | ios_base::eek:ut |
ios_base::app);
}
/* ... */

That kinda does what I wanted to do - the only thing I don't like being
that it throws the exception when the failbit is SET - and I really
would have preferred if the exception was thrown when a succeeding
operation failed _because_ of the set failbit :/
That said, I'm pretty flakey about the details.
Np, that's what references are for - you pointed me in the right
direction :)

Best Regards,

Lars
 

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,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top