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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:37:30+00:00 2026-05-19T02:37:30+00:00

It is well known that the user can define stream manipulators like this: ostream&

  • 0

It is well known that the user can define stream manipulators like this:

ostream& tab(ostream & output)
{
    return output<< '\t';
} 

And this can be used in main() like this:

cout<<'a'<<tab<<'b'<<'c'<<endl;

Please explain me how does this all work? If operator<< assumes as a second parameter a pointer to the function that takes and returns ostream &, then please explain my why it is necessary? What would be wrong if the function does not take and return ostream & but it was void instead of ostream &?

Also it is interesting why “dec”, “hex” manipulators take effect until I don’t change between them, but user defined manipulators should be always used in order to take effect for each streaming?

  • 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-05-19T02:37:31+00:00Added an answer on May 19, 2026 at 2:37 am

    The standard defines the following operator<< overload in the basic_ostream class template:

    basic_ostream<charT,traits>& operator<<(
        basic_ostream<charT,traits>& (*pf) (basic_ostream<charT,traits>&) );
    

    Effects: None. Does not behave as a formatted output function (as described in 27.6.2.5.1).

    Returns: pf(*this).

    The parameter is a pointer to a function taking and returning a reference to a std::ostream.

    This means that you can “stream” a function with this signature to an ostream object and it has the effect of calling that function on the stream. If you use the name of a function in an expression then it is (usually) converted to a pointer to that function.

    std::hex is an std::ios_base manipulator defined as follows.

       ios_base& hex(ios_base& str);
    

    Effects: Calls str.setf(ios_base::hex, ios_base::basefield).

    Returns: str.

    This means that streaming hex to an ostream will set the output base formatting flags to output numbers in hexadecimal. The manipulator doesn’t output anything itself.

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

Sidebar

Related Questions

I am wondering if there are any well-known algorithms that I should be aware
I'm building a part of a system where the user can define views from
It's a pretty popular and well known phrase that you should only catch/throw exceptions
As well-known, C++ has steeper learning curve than most of the mainstream languages, which
LAMP is a well-known acronym for the software/technology bundle/stack representing Linux , Apache ,
It is a well known problem to every web developer. As far as I
A Java version of this question was just answered, and, well, I don't know
I have a fundamental misunderstanding of SSL/TLS that I am hoping can be cleared
Say I want to have a server that can accept 2GB file over network,
I know that in the next version of ASP.NET we'll finally be able to

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.