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 6087039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:49:28+00:00 2026-05-23T11:49:28+00:00

How can I derive my own stream from a standard stream? In C# language,

  • 0

How can I derive my own stream from a standard stream?

In C# language, there is a Stream class, but C++’s streams are too complex.

I want something like this:

class my_stream : public std::stream
{
  // How to derive?
};

void using_a_stream(std::stream* s)
{
  *s << "Hello world";
}

void main()
{
  std::stream s1;
  std::fstream s2("C:\\test.txt");
  my_stream s3;

  using_a_stream(&s1);
  using_a_stream(&s2);
  using_a_stream(&s3);
}

Note: The code just a sample and may be invalid C++ program.
Thanks.

  • 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-23T11:49:29+00:00Added an answer on May 23, 2026 at 11:49 am

    I think there are three levels of answer to this question:

    Level 1: It is complicated, especially if you are completely new to C++, stop right now. Only if you feel adventurous, continue to level 2.

    Level 2: Use some library that makes creating streams easier. I would suggest using Boost.IOStreams library. It makes creating own streams and streambufs much easier. If you are still not satisfied, continue to level 3.

    Level 3: You will have to derive from std::streambuf and modify its behaviour to suit your needs. Then you will have to plug your streambuf into own stream.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please derive a concrete example from the following: http://www.urdalen.com/blog/?p=210 ..that shows how
I want to derive a stringstream so that I can use the operator<< to
Extension methods are useful for types that you don't own and can't/don't want to
Can I save page pictures from GreaseMonkey script directly to my hard drive? Is
In my app, I have deal with several different parameters, which derive from IParameter
I have my own control derived from Windows.Forms.Control and I am checking the Parent.BackColor
What do I have to do to implement my own stream, which uses custom
As part of a project I have a class which derives from NetworkStream. In
I'm trying to derive from the Silverlight Panel control to add some custom logic
I am trying to extend the Bitmap class so that I can apply my

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.