Error in building solution in VC++ 2008

Pages: 12
I'm working in Visual C++ 2008. I have a made a project in which, I'm trying to write some output and then display it on console window. Unfortunately, Every time I compile my project, it never completely compiles and ends up giving me an error saying

"DEBUG ASSERTION FAILED!"

Expression Vector subscript out of range 


After that, I get the error in windows 7 saying
"Proj.exe has has stopped working" 
.

The thing is that even if I use Arrays instead of vectors, I don't get the vector subscript out of range error but I still get
"Proj.exe has has stopped working" 
.

Can anyone please tell me why does this happen and how can I make sure this doesn't happen again?

Get Dev C++ :) (Though some people don't like it because it is kinda old).

You could also get Cygwin, Code::Blocks, or MinGW are also highly recommended compilers/IDE's.

It sounds to me like Visual studio is doing its trademark, mishandling of projects where you have to copy and paste all the code into a new project to fix it.
Last edited on
Yikes, copy and paste the entire Project?

I ran it again and this time I got the following Error.



This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Press any key to continue . . .



So you think its a compiler issue?
That sounds like a runtime bug to me.

I recommend you Google this:
Expression Vector subscript out of range


EDIT: Do NOT switch to Dev C++. Visual Studio 2008 is a considerably better product.

-Albatross
Last edited on
Yeah, I think I'm agreeing with Albatross now (Though I still recommend the switch :)). It says that you are asking the program to exit strangely, would you mind pasting any areas of your code that would cause your program to end (e.g. the end of the main, any code that waits for input like "esc" for exiting)
Post your code. Don't switch to Dev-C++
BTW, how are you able to run it when it doesn't compile? Are you starting the old executable? That may explain why it 'whines' about things that aren't in your code (anymore).
Expression Vector subscript out of range


This means that you are trying to index past the end of a vector.
For example, the vector may only have 6 objects in it but you are trying to get an object beyond that.

The fact that it also does not work for arrays confirms that suspicion.
Last edited on
Thanks a lot everybody for your reply.

I was getting the
Expression Vector subscript out of range


error because I was trying to do

sizeof(vector_name)/sizeof(int) I know now that its wrong and this is what was causing the error. I know that I can use vector_name.size() and once I did, the
Expression Vector
error was gone.

However, it still gave me problems and I still got the error
Proj.exe error and windows is shutting it down
. It got soooooo annoying that I downloaded and tried Dev C++. Works fine for now. The following is the error I was getting.

I gotta be honest, I found Dev C++ to be quite fast, and Ok so far. Though I'd still like to use VC++ but if its gonna keep on giving me those kinda stupid errors, then obviously I ain't using it.

WOW GUYS! what's with the hatred for Dev C++? I think the programming language C++ is still the same. So why sooooooooo much preference of a compiler?
I think there is a problem with the code.

for example this code
1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;

int main() {
	
	int *p;
	delete p;
	return 0;
}

This will compile and run fine on Dev-C++ yeah that's great!
but yeah Mingw (the compiler use by Dev-C++) will give you a warning about this code.

Sure this will also compile on Visual C++ but when you run, it will complain something like this
Run-Time Check Failure #3 - The variable 'p' is being used without being initialized.


So Dev-C++ is really useful isn't it? I hope you know what I mean.
blackcoder the problem with the snippet you posted ist that int *p; gets initilalized to a random value i.e.: 0x1 and then delete p; will try to delete the memory at 0x1 and this WILL fail. Mingw is allowed to pre-initialize it with 0x0 and this would not crash your programm, since delete 0x0 is allowed (it does nothing).

In VS in debug mode you will see int *p initialized with 0xcccccccc this is the default debug value for pointers in VS and deleting this address is not legal.

The run-time check is also a warning when you are compiling your code (at least in VS).
closed account (z05DSL3A)
TheTSPSolver wrote:
WOW GUYS! what's with the hatred for Dev C++? I think the programming language C++ is still the same. So why sooooooooo much preference of a compiler?


What's with the hatred for Dev C++? I have used it!
I used to have it installed for doing code snippets and such but even for that it was not that good. Apart from the compiler needing to be updated, the editor 'has issues' and as an IDE it is limited. Yes, new programmers like its simplicity, experience will undoubtedly lead to hatred of it.

The thing that really bothers me about people recommending Dev C++ is the reasoning behind it. You get a debug assertion error and the advise is to change IDE to Dev C++. This is often followed up with a paragraph that shows a lack of understanding on the part of the person giving the advice.
@RedX
Mingw is allowed to pre-initialize it with 0x0 and this would not crash your programm, since delete 0x0 is allowed (it does nothing).
Sorry, I didn't know that. Thanks for correcting me anyway.

+1 Grey Wolf
closed account (z05DSL3A)
TheTSPSolver wrote:
Though I'd still like to use VC++ but if its gonna keep on giving me those kinda stupid errors, then obviously I ain't using it.

Would that be those kinda stupid errors that are telling you your code is cocking up?
+1 Grey Wolf
Before we flame him even more. Might i suggest that he pastes some code first?
Good idea. So let's see the code first.
closed account (z05DSL3A)
Who's flaming? I was being sarcastic, whole different thing is sarcasm. ;0)
Here's the reason we hate Dev C++: It's been a long time since the last release. That means a LOT.

VC++ gives excellent errors provided you can understand them. If you can't, just google the phrase and you'll find your solution. It was that simple for me.

MinGW is an excellent compiler, but the version used in Dev C++ is far too old.

+= Grey Wolf.

And, we wouldn't mind seeing the code.

-Albatross
Last edited on
Well, it sounds like I've been effectively shut up :D.

I apologize for the un-intelligable response to this question, I have a long standing bias against microsoft products as I've personally never been satisfied with them. But I can see where Dev C++ also has plenty of problems (I personally run Linux and gcc). I did suggest that the OP should post code because with the information we were provided the best suggestion I could make was that something is wrong with the compiler or, as albatross suggested, a run-time error; though nothing could be correctly diagnosed without code to show what specifficaly is wrong.

I withdraw from this post and will let my more experienced comrads take over.
Pages: 12