| | |
Assertion failed, string subscript out of range
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2008
Posts: 32
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Nov 2008
Posts: 397
Reputation:
Solved Threads: 72
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
(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
(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
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.
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
![]() |
Similar Threads
- Problem-subscript out of range (Visual Basic 4 / 5 / 6)
- "Assertion Failed. Expression 'stream != NULL' " (C++)
- Debug Assertion Failed! (C++)
- Debug assertion failed (C++)
- vector subscript out of range (C++)
- Assertion Failed (C++)
- List of Primes (C++)
- infile into array and sort (C++)
Other Threads in the C++ Forum
- Previous Thread: C++ Using time.h [HELP !]
- Next Thread: Help with parsing strings of ints
Views: 292 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll download dynamic encryption error file forms fstream function functions game givemetehcodez google graph gui iamthwee ifstream input int integer java lib library linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project python random read recursion recursive reference return sort stream string strings struct studio system template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





