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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:34:40+00:00 2026-05-25T00:34:40+00:00

Im currently anwsering exercise questions concerning operator overloading in C++. I have a question:

  • 0

Im currently anwsering exercise questions concerning operator overloading in C++. I have a question:

Create a simple class containing an int and overload the operator+ as a member function. Also provide a print( ) member function that takes an ostream& as an argument and prints to that ostream&. Test your class to show that it works correctly.

I can create the class and write the operator+ function alright but I really dont understand the second part of the question. So far in my study of c++ I havent really come across ostream’s and as such am not sure if its possible to explicitly create such a stream. I have tried using:

std::ostream o;

However this produces an error. Could someone please enlighten me on how I should create this function please?

  • 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-25T00:34:41+00:00Added an answer on May 25, 2026 at 12:34 am

    So far in my study of c++ I havent really come across ostream’s and as
    such am not sure if its possible to explicitly create such a stream. I
    have tried using: std::ostream o;

    You must have missed something, because ostreams are important. std::cout is a variable of type std::ostream by the way. Usage is more or less like this

    #include <iostream> //defines "std::ostream", and creates "std::ofstream std::cout"
    #include <fstream> //defines "std::ofstream" (a type of std::ostream)
    std::ostream& doStuffWithStream(std::ostream &out) { //defines a function
        out << "apples!";
        return out;
    }
    int main() {
        std::cout << "starting!\n"; 
        doStuffWithStream(std::cout); //uses the function
    
        std::ofstream fileout("C:/myfile.txt"); //creates a "std::ofstream"
        doStuffWithStream(fileout); //uses the function
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a simple app that includes user authentication through devise and a
I have a following question. We are currently trying to select an appropriate structure
Currently, I don't really have a good method of debugging JavaScript in Internet Explorer and
Currently we have a hybrid ASP/PHP setup connecting to a SQL Server 2005 database.
Currently we have a project with a standard subversion repository layout of: ./trunk ./branches
I'm currently trying to have my 1and1 host an .htaccess file with mod_rewrite enabled,
The application I'm currently writing is using MVVM with the ViewModel-first pattern. I have
Let's suppose I have a widget class: struct Widget { public Color Color {
I'm currently working on adding memcache to an app running on GAE/J. I have
I'm currently writing something of a quiz program. This program throws questions at 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.