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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:25:42+00:00 2026-06-12T10:25:42+00:00

I come from a C# and Java background into C++ and I’m trying to

  • 0

I come from a C# and Java background into C++ and I’m trying to get to understand the >> & << operators such as in

std::cout << "Hello World";

What I can’t understand in here is what the << operator is for. I tried declaring my own simple function that always returns the integer 5 and I can call it as I did in C#,

int x = MyFunction();

and that turns x into 5, but why do I need to use std::cout with <<? Also I would really appreciate it if you helped me understand what both >> and << are for.

Thanks to all of you for helping me understand this. What actually opened my mind is the fact that std::cout is and object 🙂

  • 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-12T10:25:43+00:00Added an answer on June 12, 2026 at 10:25 am

    You didn’t spell it out exactly, but I believe that your confusion is that you think that std::cout is a function, and you’re wondering why you don’t just call it like this:

    std::cout("Hello World");
    

    Well, std::cout is not a function. The function in this statement is operator<<.

    std::cout << "Hello World";
    

    Or, more specifically, the function is std::ostream::operator<<(const char*).

    The thing you need to understand is that operators are just functions with an alternative calling syntax. operator<< is overloaded as a member function of std::ostream, and std::cout is an object of std::ostream. So this:

    std::cout << "Hello World";
    

    Is an alternative way to call this:

    std::cout.operator<<("Hello World");
    

    Note that operator<< is a binary operator, which means it takes two arguments, if it’s declared as a free function, and one argument if it is declared as a member function. When you use the alternative calling syntax, the object on the left is the first argument, and the object on the right is the second argument. In the case where it is declared as a member function, as it is in this case, the object on the left is the calling object, and the object on the right is the argument.

    Here’s what it would look like if it were declared as a free function:

    operator<<(std::cout, "Hello World");
    

    But, whether it is declared as a member or a free function, you can still use the same alternative calling syntax.

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

Sidebar

Related Questions

I come from a Java/C++ OOP background and am trying to get into JavaScript
I come from a Java background and am getting more into .NET, what are
I'm new to PHP but come from a Java background and I'm trying to
I come from a Java background and I am now trying to study PHP
I come from a Java background, and am very used to wrapping code into
I come from a Java/AS3/Javascript background where all of my classes are organized into
I come from Java Background and so used to Debugging using Eclipse but have
I come from a Java background and have been using C# for the last
I've come from a java background, so i'm still getting to grips with some
Let me preface this with, I come from a Java background. What is the

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.