Debug Assertion Failed

I have no idea what is wrong with my code. I have looked over it numerous times and i still don't know why i still have this problem.

Expression: string subscript out of range


 
Last edited on
The subscript is the index used to access an element of an array (the value passed into [ ]), so that being out of range means you're trying to access an element outside the range of the array.

I haven't combed through the code but there's an issue immediately at the beginning. The output variable has a size of 0 yet you're trying to access elements that don't exist (line 16). Strings can only use subscripts to access elements that already exist, they can't be used to add elements (e.g. output[3] doesn't exist, the string isn't 3 long).

There are a few alternatives you could use but the most immediate fix would be to use the push_back function instead (such as output.push_back('*'); ) but I suggest checking out this sites reference for std::string, it's rather useful to learn what the various functions can do for you (with example code to boot).
Last edited on
THanks SOLVED THE PROBLEM !
Topic archived. No new replies allowed.