Not sure that this is the right place to post this since it may be IDE specific. I apologize if it belongs somewhere else. I originally wrote this in xcode and it worked fine - in Visual Studios 2012 however I get a runtime error.
I have a program that will compile and run correctly until a certain entry is input. The error that I am getting is the following:
Debug Assertion Failed!
File: c:\program files (x86)\microsoft visual studio
Expression: string subscript out of range
For more information on how your program can cause an assertion
failure, see the visual c++ doccumentation on asserts.
This project is a conversion program that takes a roman numeral string and converts is to arabic numbers. I have it set up to loop to keep asking the user for input until they give a quit command. I can enter in "I", "II", "III", "IV" and get the expected results. The minute I put in "V" or any other Roman Numeral I get the error
I have tried searching and can't figure out why I am getting that runtime error. If you think you can help - I would be happy to private message you my code. I am not going to post my code here because I know there are fellow students of mine trolling these forms looking for code to copy.
@nevermore28 - Thanks for your response. I have evaluated my statements/loops for that same issue several times and the issue is still eluding me. Here is a little snippet of a Roman numeral that may be evaluated in the string - thie roman numeral, when input, will cause that run time error.
1 2 3 4 5 6 7 8 9 10 11 12
for (size_t position = 0; position < m_length; position++) // m_length is m_inputString.size()
if(m_inputString[position - 1] == 'C')
m_total += 0;
m_total += 1000;
From what I understand from the link you posted - my statement is going out of bounds - if that is the case, can you point me in the right direction as to how to force it to stay within bounds?
@nevermore28 - Correct me if I am wrong - but wouldn't it be possible to for the location to -1? Since it will search the string for 'M' then check if the position is before it is 'C' - that means in order for the condition to be true it, 'M' would have to be at least one position after 'C'.
I may not be wrapping my head around what you are saying. Sorry, I'm new to this :)
@nevermore28 - Thanks! I see what you are talking about. If I understand you correctly then the problem is not that I am actually finding a variable in the -1 position - it's that I am checking that location to begin with.
Is there even a way to correct that with the way my code is set up? I've been racking my brain and am unable to think of one with the knowledge I have. How would I check the position before M for without going into -1 if M is in position zero??