0

Why is the error being given? [SOLVED]

When this code runs, an error is given. Why? https://code.sololearn.com/cEa7Qbs6oVZF/#cpp

6th May 2020, 8:13 PM
CeePlusPlus
CeePlusPlus - avatar
6 Respuestas
+ 3
str b; b = "bob"; and str st; st = " b ";
6th May 2020, 8:22 PM
rodwynnejones
rodwynnejones - avatar
+ 1
Not 100% sure,....but could be your trying to assign to something that not been created yet....someone maybe able to clarify....consider using a constructor in you class. There's something wrong with your 'strip' method too....comment it out and the last two "print" output ok.
6th May 2020, 8:54 PM
rodwynnejones
rodwynnejones - avatar
+ 1
@rodwynnejones, yes... i am aware of them. I am currently fixing them.
6th May 2020, 9:09 PM
CeePlusPlus
CeePlusPlus - avatar
+ 1
In line 82 u put semicolon cout << b.count('b');<< endl; Remove this semicolon which is showing in mid b.count('b')
7th May 2020, 11:19 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
@rodwynnejones Wha- Why does it work when I just change that?
6th May 2020, 8:39 PM
CeePlusPlus
CeePlusPlus - avatar
0
For your strip method....declare a temp string and append the string elements to the temp if it is NOT a space...then... assign the temp string back into original string. (not sure if that is the best way..but that's how I managed to do it).
6th May 2020, 9:46 PM
rodwynnejones
rodwynnejones - avatar