Writing to null?

B

Bryan

In unix if I want to dump some output into never never land I can do
something like:
std::eek:fstream outfile("/dev/null");

What is the equivalent in windows? /dev/null seems not to work properly.

Is it std::eek:fstream outfile("NUL")?

Thanks,
B
 
M

Mark P

Bryan said:
In unix if I want to dump some output into never never land I can do
something like:
std::eek:fstream outfile("/dev/null");

What is the equivalent in windows? /dev/null seems not to work properly.

Is it std::eek:fstream outfile("NUL")?

Thanks,
B

Not certain of this, but I would expect that you can simply default
construct an ofstream without specifying a file name.
 
J

Jacek Dziedzic

Bryan said:
In unix if I want to dump some output into never never land I can do
something like:
std::eek:fstream outfile("/dev/null");

What is the equivalent in windows? /dev/null seems not to work properly.

Is it std::eek:fstream outfile("NUL")?

Don't know about now, but back in the old DOS days you could
indeed safely write to a special file/device called "NUL".

I am not sure that you are 100% guaranteed to be able
to bind an std::eek:fstream to a "special file", but I would expect
it to work.

HTH,
- J.
 
J

James Kanze

Not certain of this, but I would expect that you can simply default
construct an ofstream without specifying a file name.

Yes, but that will result in an error; typically, an output
error will cause the code to fail. (Output errors are normally
fairly serious, except for secondary output, like logging.)

It's pretty simple to define a nulstreambuf, which emulates the
behavior of "/dev/null" exactly. (EOF for all reads, success
for all writes.) Then just create an ostream with this as the
streambuf.
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top