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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:21:52+00:00 2026-06-03T05:21:52+00:00

I don’t know why this is erroring, but I’m just trying to add something

  • 0

I don’t know why this is erroring, but I’m just trying to add something “akin” to endl so that I can throw what’s in an ostringstream to our debugger. I have the following:

class debug_stream_info
{
public:
    debug_stream_info(int errorLine, char *errorFile, int level)
        :m_errorLine(errorLine), m_errorFile(errorFile), m_logLevel(level)
    {
    }

    friend std::basic_ostringstream<char>& operator<<(std::basic_ostringstream<char>& os, debug_stream_info& debug_info);

private:
    int m_errorLine;
    std::string m_errorFile;
    int m_logLevel;

};

std::basic_ostringstream<char>& operator<<(std::basic_ostringstream<char>& os, debug_stream_info& debug_info)
{
    // Write the stream's contents to cpu_debug
    // Deleted custom logging function.  No errors here though

    // Clear the stream for re-use.
    os.str("");
    os.seekp(0);

    return os;
}

int main(int argc, char** argv)
{
    std::ostringstream myout;
    myout << "hey there" << " and some more " << "Numbers!!: " << 435 << 54.2 << " that's good for numbers" << debug_stream_info(__LINE__, __FILE__, LOG_LEVEL);

    return 0;
}

The error I’m getting is: error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'debug_stream_info' (or there is no acceptable conversion) for the line in main. This is on VS2008.

I’m including sstream, iostream, etc, and have the namespaces set up right. I’m getting no other errors. I even tried replacing all occurrances of basic_ostream with just ostringstream and there was no difference (I’ll be having a w_char version later, but I wanted the simple case to work first). I made the object on the line above and then passed a fully-constructed object on the line, and the error was exactly the same. I’ve changed the signature of the second argument to and from const with no change as well.

Any ideas on what I’m doing wrong here?

Edit: since EVERY response seems to want to put it there, I can NOT use std::ostream because I want this to work ONLY for std::ostringstream (and std::basic_ostringstream) and not for any type of output stream. Besides, the function wouldn’t compile with ostream anyways, since I’m using the os.str() method, which isn’t in ostream, only the sub-classes.

  • 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-03T05:21:53+00:00Added an answer on June 3, 2026 at 5:21 am

    The real problem with your code is that you’ve overloaded std::ostringstream rather than std::ostream. So your code would work if you write this:

    debug_stream_info info(/** blah blah**/);
    
    std::ostringstream oss;
    oss << info ; //OK
    

    However this will not work:

    oss << 1 << info; //ERROR
    

    This is compilation error because the expression oss<<1 returns an object of type std::ostream& which doesn’t have overload which takes debug_stream_info as second argument. That means if you use cast as:

    static_cast<std::ostringstream&>(oss << 1) << info; //OK
    

    then that should work again.

    So the solution is to overload std::ostream, instead of std::basic_ostringstream.

    Also, the second parameter should be const & . This is also a problem with your code.

    So write this:

    std::ostream& operator<<(std::ostream&, debug_stream_info const &);
                                                            //^^^^^^^ note this
    

    The second parameter should be const & so that you could write temporary objects to the stream.

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

Sidebar

Related Questions

I don't know whether this is really possible, but I'm trying my best. If
Don't know why but I can't find a solution to this. I have 3
I don't know if this is a well known 'thing' or something new in
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know how to explain it better but i'm trying to get a response
Don't know if anyone can help me with this or if it's even possible.
I don't know if this question is trivial or not. But after a couple
Don't know a better title but here is what im trying to do. I
Don't know if this is the right place to ask this, but I will
Don't know what to do with this error. How to add data in SQL

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.