473,387 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Getting "vector subscript out of range" error

Han
when I exe my project in vs.net2005,I got the error following:
Debug Assertion Failed!
Program:........
File:c:\program files\microsoft visual studio 8\vc\include\vector
Line:756

Expression:vector subscript out of range.

I just push_back some int less than 30 to the vector. But in the DevC+
+5.0,everything is all right. Could anyone give me some hint what is
the wrong thing i made?

Nov 13 '07 #1
4 7066
On Nov 13, 11:35 am, Han <Mingwei....@gmail.comwrote:
when I exe my project in vs.net2005,I got the error following:
Debug Assertion Failed!
Program:........
File:c:\program files\microsoft visual studio 8\vc\include\vector
Line:756

Expression:vector subscript out of range.

I just push_back some int less than 30 to the vector. But in the DevC+
+5.0,everything is all right. Could anyone give me some hint what is
the wrong thing i made?
FAQ 5.8 may help:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

Best regards,

Tom

Nov 13 '07 #2
On Nov 13, 5:35 pm, Han <Mingwei....@gmail.comwrote:
when I exe my project in vs.net2005,I got the error following:
Debug Assertion Failed!
Program:........
File:c:\program files\microsoft visual studio 8\vc\include\vector
Line:756

Expression:vector subscript out of range.

I just push_back some int less than 30 to the vector. But in the DevC+
+5.0,everything is all right. Could anyone give me some hint what is
the wrong thing i made?
You will have to post a test case - minimal compilable code that
demonstrates the problem.

Regards

Nov 13 '07 #3
On 2007-11-13 17:35, Han wrote:
when I exe my project in vs.net2005,I got the error following:
Debug Assertion Failed!
Program:........
File:c:\program files\microsoft visual studio 8\vc\include\vector
Line:756

Expression:vector subscript out of range.

I just push_back some int less than 30 to the vector. But in the DevC+
+5.0,everything is all right. Could anyone give me some hint what is
the wrong thing i made?

It is not the push_back()s that it is complaining about, it is when you
later try to access the elements in the vector. "subscript out of range"
means that you are trying to access an element that does not exist, example:

std::vector<intvec;
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
vec.push_back(4);
std::cout << vec[4]; // There is no element at index 4

The reason that DevC++ does not complain is that it does not have as
advanced debug capabilities in its library implementation, instead it
lets the program continue running with undefined behaviour (which is the
enemy of all C++ programmers).

--
Erik Wikström
Nov 13 '07 #4
Han
On 11 14 , 12 49 , diligent.sn...@gmail.com wrote:
On Nov 13, 5:35 pm, Han <Mingwei....@gmail.comwrote:
when I exe my project in vs.net2005,I got the error following:
Debug Assertion Failed!
Program:........
File:c:\program files\microsoft visual studio 8\vc\include\vector
Line:756
Expression:vector subscript out of range.
I just push_back some int less than 30 to the vector. But in the DevC+
+5.0,everything is all right. Could anyone give me some hint what is
the wrong thing i made?

You will have to post a test case - minimal compilable code that
demonstrates the problem.

Regards
Thanks,I have already found the way to avoid this problem in MSDN.
This problem is caused by the vector operator[].Instead of [],we
should use the at() more .

Nov 14 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andrew MacIntyre | last post by:
I'm seeing a bizarre situation where IndexErrors are being thrown with "tuple index out of range" error strings. The scenario is something like: l = for a, b in l: ...
5
by: eliffman | last post by:
I'm trying to populate an array with the records from a recordset. But I'm getting an error. Here's the code: Dim db As Database, qd As QueryDef, rs As Recordset Dim MyArray() As Double, i As...
2
by: jv | last post by:
I have a form that is used every day to create quotes. However, every 2 weeks or so a user would randomly get an error 9 - subscript out range message. I'm not using any array in this form. Does...
1
by: Dave | last post by:
I'm getting the following error on an EditCommand event. This code is running on production web farm and the thing is it doesn't happen all the time. If I get this error, click the back button,...
8
by: VB Programmer | last post by:
I'm acutally using VB6, not VB.NET, but I couldn't find the newsgroup for version 6.... I need help for something that should be simple. I keep getting a "subscript out of range" error and...
0
by: dalaeth | last post by:
I have searched Google high and low and haven't found anything that works. Here's my problem, hopefully someone will be able to help! I'm using 1.1 Framework, and ODP.NET 9.5.0.7 on a Windows...
8
by: sam | last post by:
hey everybody, this is my first time posting here. i'm pretty new to python and programming in general (as you'll soon work out for yourselves...) i'm trying to code a version of a selection...
11
by: arnuld | last post by:
this is the code which runs without any trouble: ----------------------------------------------------- #include <iostream> #include <string> #include <vector> struct Entry { std::string...
5
by: ubg001 | last post by:
Hey all, I am using Access 2007 and tried to import an excel file by using the Import Wizard. I completed all steps and received an error when I clicked "Finish"... the error came back as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.