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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:04:43+00:00 2026-05-31T22:04:43+00:00

I think the following code can be used to create manipulators. #include<iostream> ostream &

  • 0

I think the following code can be used to create manipulators.

#include<iostream> 
ostream & symbol(ostream & output)
{
  return output << "\tRs";
}

it is working fine. The following statement

  cout << "Total amount: " << 567 << symbol; 

gives the output

 Total amount: 567   Rs

But I didn’t understand why it is working.
I have the following information about operator overloading in C++.

  1. only existing operators can be overloaded. New operators cannot be created.
    But the symbol is not existing operator.

  2. In the statement (cout << “Total amount: ” << 567 << symbol;), it seems that << is the overloaded operator and symbol is a variable/object.
    But I didn’t declare symbol as variable/object.

  3. why are they using the return statement (return output << “\tRs”;)?. I think (return “\tRs”;) or (output << “\tRs”;) should work.( I tried but not working 🙂 )

Actually I don’t know how the above code is working. Is there anybody to explain the working of the above operator overloading?

  • 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-31T22:04:44+00:00Added an answer on May 31, 2026 at 10:04 pm

    You are passing the function symbol to the operator <<. The << will call that function on the current ostream (with the ostream object as parameter), thus achieving the result you see. (The exact version of << called is: ostream::operator<< (ostream& ( *pf )(ostream&)); — see the reference for more info)

    The return type is ostream, to allow chaining of multiple <<‘s. You would not need it technically in your particular case as << has access to the stream, but this is to keep it consistent with the operators (I think). Of course << requires this return parameter, so you have no choice 🙂

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

Sidebar

Related Questions

The following code is an example of what I think would qualify as pseudocode,
I have the following C# code to launch an outlook window. The one think
Following is some obviously-defective code for which I think the compiler should emit a
I came across the following expression in someone else's code. I think it's terrible
Given I have two File objects I can think of the following implementation: public
The following C# code is used in a service I have inherited, to convert
Consider the following code: def CalcSomething(a): if CalcSomething._cache.has_key(a): return CalcSomething._cache[a] CalcSomething._cache[a] = ReallyCalc(a) return
I think, the following can't be done in Java. But I would be happy
I'm looking to create a generic confirmation box that can be used by multiple
I have the following code wich is raising an EConvertError - can not assign

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.