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

  • Home
  • SEARCH
  • 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 134707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:39:44+00:00 2026-05-11T06:39:44+00:00

I’d like to implement a custom manipulator for ostream to do some manipulation on

  • 0

I’d like to implement a custom manipulator for ostream to do some manipulation on the next item being inserted into the stream. For example, let’s say I have a custom manipulator quote:

std::ostringstream os; std::string name('Joe'); os << 'SELECT * FROM customers WHERE name = ' << quote << name;   

The manipulator quote will quote name to produce:

SELECT * FROM customers WHERE name = 'Joe' 

How do I go about accomplishing that? Thanks.

  • 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-11T06:39:44+00:00Added an answer on May 11, 2026 at 6:39 am

    It’s particularly difficult to add a manipulator to a C++ stream, as one has no control of how the manipulator is used. One can imbue a new locale into a stream, which has a facet installed that controls how numbers are printed – but not how strings are output. And then the problem would still be how to store the quoting state safely into the stream.

    Strings are output using an operator defined in the std namespace. If you want to change the way those are printed, yet keeping the look of manipulators, you can create a proxy class:

    namespace quoting { struct quoting_proxy {     explicit quoting_proxy(std::ostream & os):os(os){}      template<typename Rhs>     friend std::ostream & operator<<(quoting_proxy const& q,                                       Rhs const& rhs) {         return q.os << rhs;     }      friend std::ostream & operator<<(quoting_proxy const& q,                                       std::string const& rhs) {         return q.os << ''' << rhs << ''';     }      friend std::ostream & operator<<(quoting_proxy const& q,                                       char const* rhs) {         return q.os << ''' << rhs << ''';     } private:     std::ostream & os; };  struct quoting_creator { } quote; quoting_proxy operator<<(std::ostream & os, quoting_creator) {     return quoting_proxy(os); } }  int main() {     std::cout << quoting::quote << 'hello' << std::endl;  } 

    Which would be suitable to be used for ostream. If you want to generalize, you can make it a template too and also accept basic_stream instead of plain string. It has different behaviors to standard manipulators in some cases. Because it works by returning the proxy object, it will not work for cases like

    std::cout << quoting::quote;  std::cout << 'hello'; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 103k
  • Answers 103k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Write the WCF service as you would use <authentication mode="Windows"… May 11, 2026 at 8:26 pm
  • Editorial Team
    Editorial Team added an answer I have had good luck with phpUnderControl, which is based… May 11, 2026 at 8:26 pm
  • Editorial Team
    Editorial Team added an answer Your initial thoughts are spot on. Objects should be singular,… May 11, 2026 at 8:26 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.