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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:53:38+00:00 2026-05-11T03:53:38+00:00

I am trying to create a c++ ostream for educational reasons. My test will

  • 0

I am trying to create a c++ ostream for educational reasons. My test will be creating an ostream that acts like a ofstream would except instead of writing to a file it would write to a deque or vector container.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T03:53:39+00:00Added an answer on May 11, 2026 at 3:53 am

    As it is for education, as you say, i will show you how i would do such a thingy. Otherwise, stringstream is really the way to go.

    Sounds like you want to create a streambuf implementation that then writes to a vector / deque. Something like this (copying from another answer of me that targeted a /dev/null stream):

    template<typename Ch, typename Traits = std::char_traits<Ch>,          typename Sequence = std::vector<Ch> > struct basic_seqbuf : std::basic_streambuf<Ch, Traits> {      typedef std::basic_streambuf<Ch, Traits> base_type;      typedef typename base_type::int_type int_type;      typedef typename base_type::traits_type traits_type;       virtual int_type overflow(int_type ch) {          if(traits_type::eq_int_type(ch, traits_type::eof()))              return traits_type::eof();          c.push_back(traits_type::to_char_type(ch));          return ch;      }      Sequence const& get_sequence() const {         return c;     } protected:     Sequence c; };  // convenient typedefs typedef basic_seqbuf<char> seqbuf; typedef basic_seqbuf<wchar_t> wseqbuf; 

    You can use it like this:

    seqbuf s; std::ostream os(&s); os << 'hello, i'm ' << 22 << ' years old' << std::endl; std::vector<char> v = s.get_sequence(); 

    If you want to have a deque as sequence, you can do so:

    typedef basic_seqbuf< char, char_traits<char>, std::deque<char> > dseq_buf; 

    Or something similar… Well i haven’t tested it. But maybe that’s also a good thing – so if it contains still bugs, you can try fixing them.

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

Sidebar

Related Questions

Trying to create an framework 4.0 WCF basicHttp service hosted by IIS (6) that
I'm trying to create test users (works) and then invite them to my app
I'm trying to create a sliding checkbox like the one on the iphone. I
I've been trying to create a new variable of type Cmplx (which is my
I'm trying create a log specifically for logging user account activity. I created this
I'm trying create an immutable object and initialise it from xml config file in
Im trying to create a mixing for Ext.grid.Panel components. This is how I have
Iam trying to create a list view dynamically, Please provide me an example for
I am trying to create 3 table view cells using code (w/o nib). I
I have a situation where 2 different processes(mine C++, other done by other people

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.