Assertion failed, string subscript out of range

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 32
Reputation: hezfast2 is an unknown quantity at this point 
Solved Threads: 0
hezfast2 hezfast2 is offline Offline
Light Poster

Assertion failed, string subscript out of range

 
0
  #1
Oct 27th, 2009
Hello,
I've attached my code, I keep getting the Debug Assertion failed, Expression: string subscript out of range error

I can't find any errors in my logic and code for the functions, but obviously something is wrong, no matter where I put breaks, i still get the error when debugging. Any idea where I should look for the problem.
Attached Files
File Type: h InfixToPostfix.h (433 Bytes, 1 views)
File Type: cpp infixToPostFixImp.cpp (1.9 KB, 1 views)
File Type: h myStack.h (5.4 KB, 1 views)
File Type: cpp testProg.cpp (658 Bytes, 2 views)
File Type: txt input.txt (94 Bytes, 2 views)
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 397
Reputation: StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light 
Solved Threads: 72
StuXYZ StuXYZ is offline Offline
Posting Whiz
 
0
  #2
Oct 27th, 2009
I am not going to deal with all the things that are wrong here

They include:

(a) a missing = in a test [icode]else if (opr1 ='(')[/icode[
(b) stupid reassignment ifx[i] = ifx[i+1]; but loop on i.
(c) Failure to initialize variables and then do a test of two uninitialized variables
(d) Assuming a terminator char ( ; ) is in a string BUT then default string doesn't have it (i.e. you use ""). So test for the end of the string as well as the terminator.



However, from the code, with templates etc, you are clearly not a beginner BUT the trivial beginner errrors you are making are :
(It does seem that two different programmers wrote myStack and InfixToPostfix. -- these are the infixtopost problems

(i) Not using compiler warnings
(ii) writng using namespace std; (iii) passing everything by value not reference
(iv) Not using the keyword: const
(v) not initializing variables
(vi) not writing copy/assignment methods for complex classes.
(vii) Breaking the program down into subunits, but not testing them individually.
(viii) using varaible names like ifx , which is a minor typo away from a mess.

Number (ii) is the cause of some of your strange error messages since you use a variable called list. This is only possible IF you got the scoping correct....

The whole point of a namespace is to avoid name pollution so don't take it away.

[Rant]
When I interview programmers I ask them to write a piece of code, and if they put "using namespace std" at the top of their program, they are 99% of the way to the "no hire" bucket because they can't have (a) read much (b) writen much code.
[/Rant]




Finally a bit of maths: A/B*C/D is the same as (A/B)*(C/D). Additionally
A/B/C is not the same as (A*C)/B but the same as (A/C)/B. Fix your precedence function.
Last edited by StuXYZ; Oct 27th, 2009 at 7:20 pm.
experience is the most expensive way to learn anything
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 293 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC