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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:22:17+00:00 2026-06-12T22:22:17+00:00

Possible Duplicate: Operator overloading I’m making a long awaited return to C++ and there’s

  • 0

Possible Duplicate:
Operator overloading

I’m making a long awaited return to C++ and there’s some basic notation that doesn’t really seem to be that prominent in other languages.

If you look at this line of code

cout << "firstvalue is " << firstvalue << endl;

I realise what this does. It write’s “firstvalue is x” to the console. x being the value of firstvalue. However, I do not know anything about the “<<” or “>>” double angled brackets. I haven’t been able to research them or what they do as I don’t know the formal name for them.

My question is, what actually happens (step by step) in the above statement? And what are these “<<” for? I think I understand that cout is a standard library function for writing to the console. However I’m used to either objective-c or dot notation. I do not see what object this “cout” function is a member of.

I can understand printf a little more easily, as at least it provides braces for the arguments. e.g. printf(“your string here”).

  • 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-12T22:22:18+00:00Added an answer on June 12, 2026 at 10:22 pm

    C++ allows operator overloading. That means a user-defined type can define its own behavior on built-in operators. In this case the operators are called: left shift or right shift operators. Those operators have been traditionally been used for bit-shifting, but the standard library repurposes them to symbolize streaming operations.

    You can find a list of the available operators in C and C++ here.

    In your case you are streaming a string literal and a value of some type into std::cout, which is an object of type std::basic_ostream.

    Step-by-Step

    After precedence rules have been applied your code looks like this:

    ((cout << "foobar") << x) << endl;
    

    The compiler will basically transform the object << object expressions into function calls.

    operator<<(operator<<(operator<<(cout, "foobar"), x), endl);
    

    Then it will figure out which overload to call. (This is really
    tricky. For now it should be sufficient to believe that it simply
    looks for an overload of operator<< with matching arguments).

    Most of the built-in overloads for basic_ostream are here and here.

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

Sidebar

Related Questions

Possible Duplicate: Conditional operator in Python? Is there a c-like operator in python that
Possible Duplicate: Operator overloading I didn't find any thing that could help me in
Possible Duplicate: Overloading operator -> Hi, I've seen that operator->() is chained (re-applied) after
Possible Duplicate: Operator overloading Hi guys can some one please suggest a good tutorial
Possible Duplicate: Operator Overloading in PHP Is there a way to overload the =
Possible Duplicate: Operator Overloading in PHP I am trying to create a library that
Possible Duplicate: overload operator<< within a class in c++ Operator overloading Is there any
Possible Duplicate: What are the basic rules and idioms for operator overloading? Operator overloading
Possible Duplicate: Why must the copy assignment operator return a reference/const reference? Operator= overloading
Possible Duplicate: Java operator overload In c++, we can perform the operator overloading. But

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.