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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:13:41+00:00 2026-05-18T00:13:41+00:00

I overloaded the left shift operator in my class and the output works fine,

  • 0

I overloaded the left shift operator in my class and the output works fine, so for example when I have a line which says cout << obj; I will output the fields seperated by a comma.

 ostream& operator<<(ostream& output, const MyClass& obj)
 {
     output << obj.field1 << ", " << obj.field2;
     return output;
 }

I want to write a test case for this operation, but I have no idea how to compare the returned result with the expected result in cxxtest. I tried the following, but it did not work:

 TS_ASSERT_EQUALS(cout << "1, 50.0", cout << obj);

Am I supposed to use a different cxxtest operation or change the parameter passing mechanism in TS_ASSERT_EQUALS?

Note that when I output the following lines, I get the same results:

 cout << obj;
 cout << "1, 50.0";

Note: I get a bunch of compiler errors when I attempt to compile the program because TS_ASSERT_EQUALS fails.

  • 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-18T00:13:42+00:00Added an answer on May 18, 2026 at 12:13 am

    Even if it did compile, you’re basically comparing cout with itself …

    Try writing to two distinct std::stringstreams, extracting their string values, and comparing these.

    If you also need to test ostream flags, define a comparison function and use TS_ASSERT_RELATION.

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

Sidebar

Related Questions

I have an overloaded << operator from my reckful class implemented as follows: ostream&
I have a vector class with a properly overloaded Vect*float operator and am trying
Because I've overloaded the operator++ for an iterator class template<typename T> typename list<T>::iterator& list<T>::iterator::operator++()
How can I invoke overloaded generic method in IronRuby? I have a .NET class
I have an overloaded function which I want to pass along wrapped in a
I have a class with a template parameter which should decide which of two
Error: error C2678: binary '==' : no operator found which takes a left-hand operand
If you overload - like operator-(), it is to be used to the left
If I've overloaded operator+ and operator= do I still need to overload operator+= for
I have an overloaded action in my Controller: public ActionResult AssignList(int id) { ...

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.