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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:38:10+00:00 2026-06-01T08:38:10+00:00

Is it possible to search the content of a std::ostringstream without using the std::ostringstream::str()

  • 0

Is it possible to search the content of a std::ostringstream without using the std::ostringstream::str() member function to create a std::string to search?

I have the following and want to avoid constructing a std::string instance on every invocation of flush_():

#include <iostream>
using std::cout;

#include <ios>
using std::boolalpha;

#include <sstream>
using std::ostringstream;

#include <string>
using std::string;

class line_decorating_ostream
{
public:
    line_decorating_ostream()  { out_ << boolalpha;  }
    ~line_decorating_ostream() { cout << out_.str(); }

    template <typename T>
    line_decorating_ostream& operator<<(const T& a_t)
    {
        out_ << a_t;
        flush_();
        return *this;
    }

private:
    ostringstream out_;
    line_decorating_ostream(const line_decorating_ostream&);
    line_decorating_ostream& operator=(const line_decorating_ostream&);

    // Write any full lines.
    void flush_()
    {
        string s(out_.str());
        size_t pos = s.find('\n');
        if (string::npos != pos)
        {
            do
            {
                cout << "line: [" << s.substr(0, pos) << "]\n";
                s = s.substr(pos + 1);

            } while (string::npos != (pos = s.find('\n')));

            out_.clear();
            out_.str("");
            out_ << boolalpha << s;
        }
    }
};

int main()
{
    line_decorating_ostream logger;

    logger << "1 " << "2 " << 3 << " 4 " << 5 << "\n"
           << "6 7 8 9 10\n...\n" << true << "\n";

    return 0;
}

[It is not causing any performance issues that I am concerned about, just curious if this is possible.]

  • 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-01T08:38:12+00:00Added an answer on June 1, 2026 at 8:38 am

    Use its streambuf class? Or write an own one? (Ok: you should write an own one: pbase and pptr are protected.)

    class my_str_buffer : public basic_stringbuf<char>
    {
      public:
        using basic_stringbuf<char>::pbase;
        using basic_stringbuf<char>::pptr;
    };
    
    my_str_buffer my_buf;
    ostream str( &my_buf );
    // do anything
    string foo( str.rdbuf()->pbase(), str.rdbuf()->pptr() );
    

    ostream constructor and stringbuf

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

Sidebar

Related Questions

I have done the python application to search the SharePoint content using SharePoint web
Basically I have three pages. -A page with all possible search results for example:
Is it possible to search on date ranges using Lucene in Java? How do
I have a question about IPTC metadata. Is it possible to search images that
Possible Duplicate: MySQL full text search with partial words I have a search feature
Is it possible to search multiple pdf files using the 'grep' command. It doesn't
Recently search engines have been able to page dynamic content on social networking sites.
Possible Duplicate: Parse XML with Namespace using SimpleXML PHP SimpleXML Namespace Problem <?php header(Content-Type:
I have a search form that the user can search for an Article content
I have a search implemented on my site, it runs the following queries: SELECT

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.