Help: ofstream issues

F

fasteddie203

Hi,

I hope this is appropriate for standard C++ group, I apologize if it is
not. I'm trying to print to LPT1 using ofstream which works fine as
long as the printer is connected - it doesn't need to be powered on.

However, if there is no printer at all, it seems the ofstream won't
detect the failure or close gracefully - but when the stream closes
(manually or when the stream's deconstructor is called) the application
hangs.

No exceptions get thrown either so I am not sure how to detect a
failure.

Here's the basic code snippets:

std::eek:fstream print;

print.open("LPT1"); //no printer is hooked up.

//None of these return
if (!print)return 0;
if (print.fail()) return 0;
if (!print.isopen()) return 0;

print.close(); //Hangs



Any help/suggestions would be appreciated.

Thanks,

Michael
 

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,744
Messages
2,569,479
Members
44,900
Latest member
Nell636132

Latest Threads

Top