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

  • Home
  • SEARCH
  • 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 7867187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:38:40+00:00 2026-06-03T00:38:40+00:00

Here are the instructions verbatim: String insertion/extraction operators (<< and >>) need to be

  • 0

Here are the instructions verbatim:

String insertion/extraction operators (<< and >>) need to be overloaded within the MyString object. These operators will also need to be capable of cascaded operations (i.e., cout << String1 << String2 or cin >> String1 >> String2). The string insertion operator (>>) will read an entire line of characters that is either terminated by an end-of-line character (\n) or 256 characters long. An input line that exceeds 256 characters will be limited to only the first 256 characters.

With that, this is the code I’ve gotten thus far:

in my .cpp file:

 istream& MyString::operator>>(istream& input, MyString& rhs)
{

    char* temp;
    int size(256);
    temp = new char[size];
    input.get(temp,size);
    rhs = MyString(temp);
    delete [] temp;

    return input;

 }

in my .h file:

istream& operator>>(istream& input, MyString& rhs);

call from main.cpp file:

   MyString String1;
  const MyString ConstString("Target string");          //Test of alternate constructor
  MyString SearchString;        //Test of default constructor that should set "Hello World"
  MyString TargetString (String1); //Test of copy constructor

  cout << "Please enter two strings. ";
  cout << "Each string needs to be shorter than 256 characters or terminated by
  /.\n" << endl;
 cout << "The first string will be searched to see whether it contains exactly the second string. " << endl;


 cin >> SearchString >> TargetString; // Test of cascaded string-extraction operator<<

The error that I get is: istream& MyString::operator>>(std::istream&, MyString&)â must take exactly one argument

How can I correct this? I am super confused on how to do this without BOTH the rhs and input

  • 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-03T00:38:43+00:00Added an answer on June 3, 2026 at 12:38 am

    You have to create the operator>> as a non-member function.

    As it is now, your function expects three arguments: the implicit invoking object, the istream&, and the MyString& rhs. However, since operator>> is a binary operator (it takes exactly two arguments) this won’t work.

    The way to do this is to make it a non-member function:

    // prototype, OUTSIDE the class definition
    istream& operator>>(istream&, MyString&);
    
    // implementation
    istream& operator>>(istream& lhs, MyString& rhs) {
        // logic
    
        return lhs;
    }
    

    And doing it that way (non-member function) is the way you have to do all operators where you want your class to be on the right side, and a class that you can’t modify on the left side.

    Also note that if you want to have that function access private or protected members of your objects, you have to declare it friend in your class definition.

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

Sidebar

Related Questions

I followed these instructions here: http://logback.qos.ch/consolePlugin.html I have the correct and found logback.xml, it
I am building a Httphandler following these instructions here It manipulates HTTP POST and
I followed these instructions here: http://w3schools.com/razor/razor_example.asp NOTE: I'm using Web Matrix The example said
There are instructions here to create a C# assembly using the SimMetrics library. The
Tried following the instructions here: How to use Google app engine with my own
I followed the instructions here http://support.microsoft.com/kb/825532 After that when I preview my page, I
I have followed all the instructions here: http://www.tonyspencer.com/2003/10/22/curl-with-php-and-apache-on-windows/ to install & config apache get
I have followed the instructions here: http://help.github.com/win-set-up-git/ to set up git on my windows
I'm trying to follow the instructions here ( http://docs.pylonsproject.org/projects/pyramid_beaker/en/latest/ ) so I can setup
I'm setting up a net.tcp WCF service using instructions here: http://blogs.msdn.com/swiss_dpe_team/archive/2008/02/08/iis-7-support-for-non-http-protocols.aspx One of 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.