Re: vector subscript out of range
On 11 Maj, 07:27, Andy <fru...@gmail.com> wrote:
with vector.begin and vector.end - so I wonder why this error happens.
And what would you have us do? guess?
Can't you simply write a simple test program that iterates through the
vector's elements and recreates the problem? And post it? Any chance
that you compiled the program on Windows in debug mode (assuming
assertions won't trigger in release mode on that MAC?) Did you know
that vector has the at() member function that throws an exception when
'subscript' is out of range in both debug and release mode? What
version of VC++ is involved?
Why is it that these questions need be asked at all?
perhaps I am not in that detail about my question - cuz I am new to c+
+ and also new to this group.
Since you are new I'll forgive you this once, but in the future please
don't top-post, see http://www.parashift.com/c++-faq-lite/how-to-post.html
for more information.
On the Mac the error does not appear - also when I compile it in
Release mode. Everything works fine
Yes, I compiled it on Windows in Debug Mode
I will take a look at the at() member
I also use sometimes things like that instead of an iterator
(for i=0; i < vector.size(); i++) { ... }
(for i=vector.size()-1; i>0 ;i--) { ... }
The last one looks fishy, are you aware of the fact that it will not
process the first element in the vector? Use reverse_iterators
instead, then you don't have to worry about at what index to start and
end.
I am using MS Visual C++ Express Edition on Windows XP Pro
The standard library in VC++ 2005 comes with checked iterators, which
performs basic checks to see if iterators are out of range but also if
the [] operator is out of range, so if you get that kind of errors you
are probably doing something wrong and can count yourself lucky that
it has been working so far on the Mac. Try to use iterators as much as
possible and at() instead of [] and you should be able to find your
problem, another way might be to run the application in debug mode and
see where it crashes.
--
Erik Wikstr=F6m