Mar 23, 2015 at 6:44pm Mar 23, 2015 at 6:44pm UTC
I am stuck on my getline function. I need it to output to a delimiter, and it does store up to the delimiter, but it continues to output.
This is the function:
1 2 3 4 5 6 7 8 9 10 11 12 13
{
int num= 0;
char sp = ' ' ;
char * t = new char [min];
while (a.peek() != '\n' )
{
a >> t[num];
num++;
return a;
}
How could i fix this to only output the words, and not the random characters as well?
Last edited on Mar 25, 2015 at 3:42pm Mar 25, 2015 at 3:42pm UTC
Mar 23, 2015 at 7:22pm Mar 23, 2015 at 7:22pm UTC
What is xString and why are you not using std::string ?
Mar 23, 2015 at 7:32pm Mar 23, 2015 at 7:32pm UTC
I made a string class on my own using dynamic memory allocation and arrays of characters, xString is that class.
and it does compile.
Last edited on Mar 25, 2015 at 3:41pm Mar 25, 2015 at 3:41pm UTC
Mar 23, 2015 at 7:33pm Mar 23, 2015 at 7:33pm UTC
Most likely, your custom string implementation has a mistake that results in memory corruption. Use std::string instead of reinventing the wheel.
Mar 23, 2015 at 7:42pm Mar 23, 2015 at 7:42pm UTC
My assignment calls for me to make my own string class, hence the lack of strings.
Mar 23, 2015 at 8:06pm Mar 23, 2015 at 8:06pm UTC
You should then look through your string class code for mistakes.
Mar 24, 2015 at 7:51am Mar 24, 2015 at 7:51am UTC
You should really consider using std::string
Mar 24, 2015 at 7:26pm Mar 24, 2015 at 7:26pm UTC
I would be willing to correct your getline if possible, post the definition of your class then i'll check see if it's possible to get it working.
Mar 25, 2015 at 11:28am Mar 25, 2015 at 11:28am UTC
Oh my bad,didn't see that.:)