File cannot open with ofstream constructor !

T

tornado

hi all,

This is quite puzzling me why is that ofstream constructor is unable
to open a file for writing while, a ofstream "open" method can ! The
c++ book by Herbert Schildt which i m readin mentions that ofstream
default constructor can open a file. But when i tried to open a file
it failed to open. Then i tried it by open method which succeded.
I m using g++ on Redhat linux.

Any insights will be appreciated.
Thanks in advance.
 
M

Mike Wahler

tornado said:
hi all,

This is quite puzzling me why is that ofstream constructor is unable
to open a file for writing while, a ofstream "open" method can !

Show us your code.
The
c++ book by Herbert Schildt

See http://snurse-l.org/acllc-c++/faq.html#q6.4
which i m readin mentions that ofstream
default constructor can open a file.

Did you misread that part, or is this another 'Schildtism'?
Class 'ofstream' does provide a default constructor, but
it certainly does not open a file? Which file would it open?
But when i tried to open a file
it failed to open.

Show us the code you used, and tell us what indicates
to you the open failed.
Then i tried it by open method which succeded.
I m using g++ on Redhat linux.

Any insights will be appreciated.

Show us a small, compilable example program which
exhibits the problem behavior, and perhaps we can
help.

-Mike
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top