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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:10:09+00:00 2026-06-09T05:10:09+00:00

I have a Visual Studio 2008 C++ 03 application using STLPort 5.2.1 where I

  • 0

I have a Visual Studio 2008 C++ 03 application using STLPort 5.2.1 where I would like to use a custom std::filebuf implementation. For example:

class MyFileBuf : public std::filebuf
{
protected:
    virtual int_type sync()
    {
        // breakpoint here never fires
        return std::filebuf::sync();
    };

    virtual std::streamsize xsputn( const char_type* p, std::streamsize n )
    {
        // breakpoint here never fires
        return std::filebuf::xsputn( p, n );
    };

    virtual int_type overflow( int_type c = traits_type::eof() )
    {
        // breakpoint here never fires
        return std::filebuf::overflow( c );
    };
};

class MyFileStream : public std::ofstream
{
public:
    MyFileStream() : std::ofstream( new MyFileBuf() ) { clear(); };
    ~MyFileStream() { delete rdbuf(); };
};

int main()
{
    MyFileStream fs;
    fs.open( "test.txt" );
    fs << "this is a test" << std::endl;
    return 0;
}

Unfortunately, none of the members of MyFileBuf are ever called. If I step through the code, I see that the << operator goes to

stlpd_std::basic_streambuf<char,stlpd_std::char_traits<char> >::xsputn(const char* __s, long int __n)
stlpd_std::basic_streambuf<char,stlpd_std::char_traits<char> >::sputn(const char* __s, long int __n)
stlpd_std::basic_ostream<char,stlpd_std::char_traits<char> >::_M_put_nowiden(const char* __s)
stlpd_std::operator<<<stlpd_std::char_traits<char> >(stlpd_std::basic_ostream<char,stlpd_std::char_traits<char> >& , const char* __s )
main()

where I would expect the top of the callstack to be:

MyFileBuf::xsputn(const char* p, long int n)

The files are, however, written correctly. Can anybody help me understand where I am going wrong?

  • 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-06-09T05:10:12+00:00Added an answer on June 9, 2026 at 5:10 am

    Thanks @jahhaj and @DanielKO for your help.

    The solution appears to be something like this:

    #include <iostream>
    #include <fstream>
    using namespace std;
    
    class MyFileBuf : public std::filebuf
    {
    protected:
        virtual int_type sync()
        {
            return std::filebuf::sync();
        };
    
        virtual std::streamsize xsputn( const char_type* p, std::streamsize n )
        {
            return std::filebuf::xsputn( p, n );
        };
    
        virtual int_type overflow( int_type c = traits_type::eof() )
        {
            return std::filebuf::overflow( c );
        };
    };
    
    class MyFileStream : public std::ostream
    {
    public:
        MyFileStream() : std::ostream( 0 ) { init( &buf_ ); };
        MyFileStream( const char* filename, std::ios_base::openmode mode = std::ios_base::out )
            : std::ostream( 0 )
        {
            init( &buf_ );
            this->open( filename, mode );
        }
    
        bool is_open() const { return buf_.is_open(); };
    
        void close() { buf_.close(); };
    
        void open( const char* filename, std::ios_base::openmode mode = std::ios_base::out )
        {
            buf_.open( filename, mode );
        };
    
        std::filebuf* rdbuf() { return &buf_; };
    
    private:
        MyFileBuf buf_;
    };
    
    int main()
    {
        MyFileStream fs( "test.txt" );
        fs << "this is a test" << std::endl;
        return 0;
    }
    

    Example

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

Sidebar

Related Questions

I have a Visual Studio 2008 C++ application where I'm using a custom allocator
I have a Visual Studio 2008 C++ application where I would like to insert
I have a Visual Studio 2008 C++ application where I would like to replace
I developed a WinForms application (using C#, with visual studio 2008) and I have
I'm using Visual Studio 2008 and have created a setup project for my application.
Using Visual Studio 2008, c#, .net 2.0. I have a Windows Forms client application
I am using working on a c++ application in Visual studio 2008 I have
I have a Visual Studio 2008 C++ application that does something like this: template<
I have a Visual Studio 2008 Windows Mobile 6 C++ application that is using
I have developed an application using VB.NET, Visual Studio 2008 and the SQL Server

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.