Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m having trouble immplimenting the >> operator in a self made string class fo

ID: 3545249 • Letter: I

Question

I'm having trouble immplimenting the >> operator in a self made string class for my Cmpsci homework. I currently have


std::istream& operator >> (std::istream& in, String& myString)

{

char input[1];

String inputString;

do

{

in >> input[0];

inputString[1] = 0;

inputString = input[0];

myString = myString + inputString;

}while(input[0] != '/n');

return in;

}


I've been fiddling with trying to use an array. I run into issues when the class constructor tries to get the length, as it just runs to infinity and turns up a memory error. My included files are the "String.h", <sstream>, and <iostream>. How can I properly impliment this operator?


P.S. We are required to use a self-made string class, and as such the STL string is off limits


Thanks

Explanation / Answer

ur using the ">>" operator within ur code:
in >> input[0];

thts the reason it runs in an infinite loop

use some other way to fetch data from a stream, maybe like istream::read function or istream::getline function

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote