Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6687397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:17:03+00:00 2026-05-26T05:17:03+00:00

I’d like to send data to nowhere, I mean that I don’t want to

  • 0

I’d like to send data to nowhere, I mean that I don’t want to print data in console nor in file, but I need some std::ostream object. How to do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:17:03+00:00Added an answer on May 26, 2026 at 5:17 am

    I’ve used:

    std::ostream bitBucket(0);
    

    recently without problems, although it was flagged as having some potential problems if you looked at it from a certain angle (see the link below).

    Aside: From what I understand (and I’m not entirely sure of this), that call above eventually ends up calling basic_ios::init(0) and, because that’s a NULL pointer being passed in, it sets the stream state, as returned by the rdstate() function, to the badbit value.

    This in turn prevents the stream from outputting any more information, instead just tossing it away.

    The following program shows it in action:

    #include <iostream>
    
    int main (void) {
        std::ostream bitBucket(0);
        bitBucket << "Hello, there!" << std::endl;
        return 0;
    }
    

    The page where I got it from also had this as a probably-cleaner solution (slightly modified to remove the duplication of my first solution above):

    #include <iostream>
    
    class null_out_buf : public std::streambuf {
        public:
            virtual std::streamsize xsputn (const char * s, std::streamsize n) {
                return n;
            }
            virtual int overflow (int c) {
                return 1;
            }
    };
    
    class null_out_stream : public std::ostream {
        public:
            null_out_stream() : std::ostream (&buf) {}
        private:
            null_out_buf buf;
    };
    
    null_out_stream cnul;       // My null stream.
    
    int main (void) {
        std::cout << std::boolalpha;
    
        //testing nul
    
        std::cout << "Nul stream before: " << cnul.fail() << std::endl;
        cnul << "Goodbye World!" << std::endl;
        std::cout << "Nul stream after: " << cnul.fail() << std::endl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I want to construct a data frame in an Rcpp function, but when I
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.