Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Writing to null?

Reply
Thread Tools

Writing to null?

 
 
Bryan
Guest
Posts: n/a
 
      04-18-2007
In unix if I want to dump some output into never never land I can do
something like:
std:fstream outfile("/dev/null");

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

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

Thanks,
B
 
Reply With Quote
 
 
 
 
Mark P
Guest
Posts: n/a
 
      04-19-2007
Bryan wrote:
> In unix if I want to dump some output into never never land I can do
> something like:
> std:fstream outfile("/dev/null");
>
> What is the equivalent in windows? /dev/null seems not to work properly.
>
> Is it std: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.
 
Reply With Quote
 
 
 
 
Jacek Dziedzic
Guest
Posts: n/a
 
      04-19-2007
Bryan wrote:
> In unix if I want to dump some output into never never land I can do
> something like:
> std:fstream outfile("/dev/null");
>
> What is the equivalent in windows? /dev/null seems not to work properly.
>
> Is it std: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:fstream to a "special file", but I would expect
it to work.

HTH,
- J.
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      04-19-2007
On Apr 19, 2:13 am, Mark P <(E-Mail Removed)>
wrote:
> Bryan wrote:
> > In unix if I want to dump some output into never never land I can do
> > something like:
> > std:fstream outfile("/dev/null");


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


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


> 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.

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing a program to create a wireless connection. =?Utf-8?B?bWJvd3llckBwdXJkdWUuZWR1?= Wireless Networking 1 10-05-2005 12:59 PM
writing email problems? Bri Firefox 1 05-12-2005 03:03 AM
Any problems with writing the information into a file - Multi-users perform writing the same file at the same time ???? HNguyen ASP .Net 4 12-21-2004 01:53 PM
Unhandled exception in FileStream when writing to a full disk - bug in framework? Amit ASP .Net 8 08-04-2003 03:34 PM
A failure occurred writing to the resources file. Access is denied. -- RESX file is locked? -- WHY? Mark Kamoski ASP .Net 1 07-04-2003 12:02 PM



Advertisments