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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:42:06+00:00 2026-05-25T12:42:06+00:00

I am testing some C++ code related to overloading IO operators. The code as

  • 0

I am testing some C++ code related to overloading IO operators. The code as follows:

class Student {
 private:
     int no;
 public:
     Student(int n)
     {
         this->no = n;
     }
     int getNo() const {
         return this->no;
     }
     friend istream& operator>>(istream& is, Student& s);
     friend ostream& operator<<(ostream& os, const Student& s);
 };
 ostream& operator<<(ostream& os, const Student& s){
     cout << s.getNo(); // use cout instead of os
     return os;
}
istream& operator>>(istream& is, Student& s) 
{
    cin >> s.no; // use cin instead of is
    return is;
}

However, inside the << and >>, I can use:

 ostream& operator<<(ostream& os, const Student& s){
     os << s.getNo(); // use os instead of cout
     return os;
}
istream& operator>>(istream& is, Student& s) 
{
    is >> s.no; // use is instead of cin
    return is;
}

In <<, I use os object instead of cout and the similarity for >> operator. So, I am curious to know if there is any difference of that?

  • 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-25T12:42:06+00:00Added an answer on May 25, 2026 at 12:42 pm

    The difference is obvious, is/os are input/output streams while cin/cout are the standard input/output streams. cin/cout are instances of i/o streams, not synonyms.

    The point being, there are streams other than standard input/output, such as files, string streams, and whatever custom implementation you can think of. If you use cin/cout in your streaming operators, ignoring the stream they should read/write to, then you’ll end up with

    file_stream << some_student;
    

    printing to the standard output, rather than to the file where its supposed to.

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

Sidebar

Related Questions

I'm testing some legacy code that extends the default php exception object. This code
For some testing code, I'd like to be able to host a WCF service
I am testing some weird-looking CSS code that I wrote (I'm using a mix
I am starting to write some code for A/B testing in a Grails web
I've been trying to implement unit testing and currently have some code that does
Code and preview: <html> <head> <title>Testing some CSS</title> <style type=text/css> .dDay { font-size:205% }
I'm doing some unit testing, and some of the code is checking to see
Sometimes for testing/developing purposes we make some changes in the code that must be
Hi I'm testing some CRUD operations in Nhibernate. I have 3 tests in this
I have several files with code testing code (which uses a unittest class). Later

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.