RSS Forums RSS

Debug Assertion failed. help?

Please support our C++ advertiser: Programming Forums
Reply
Posts: 7
Reputation: radmaker3 is an unknown quantity at this point 
Solved Threads: 0
radmaker3 radmaker3 is offline Offline
Newbie Poster

Debug Assertion failed. help?

  #1  
Dec 15th, 2008
I just started using MS Visual C++ express to brush up on C\C++

I wrote one little sample program and it ran successfully, then every time after that i kept getting this debug assertion failed error that killed my program.

Here's my code.

#include <iostream>

using std::cout;
using std::cin;

int main(){

int int1, int2, sum; //integers 1, 2, and the sum

cout << "Hello, I will add two integers for you.";

cout << "Please enter the first number: ";
cin >> int1;

cout << "Please enter the second number: ";
cin >> int2;

sum = int1 + int2; //sum of the 2 numbers

cout << "The sum of the numbers is: " << sum;

return 0;
}

It compiles, not sure if it works, but thats not really the point. I don't know what this debug assertion failure is. Any help?
AddThis Social Bookmark Button
Reply With Quote  
Posts: 314
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 61
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Debug Assertion failed. help?

  #2  
Dec 16th, 2008
That code is a dodge, don't u..
Assert : typically used to identify logic error by implementing the expression arg to evaluate to false only..
Ex.
char ch = 'a';
assert(ch != 'a') // assertion failure..
//expression is false..
.:-cikara21-:.
Reply With Quote  
Posts: 5,126
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 633
Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Debug Assertion failed. help?

  #3  
Dec 16th, 2008
Post the text of the assertion as well.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
UK Voter? Please send a message to Incapability Brown and the rest of Zanu-Labour
Up to 8Mb PlusNet broadband from only £5.99 a month!
Reply With Quote  
Posts: 7
Reputation: radmaker3 is an unknown quantity at this point 
Solved Threads: 0
radmaker3 radmaker3 is offline Offline
Newbie Poster

Re: Debug Assertion failed. help?

  #4  
Dec 16th, 2008
I simplified the code to this and still got the error.
#include <iostream>

using std::cout;

int main(){

	cout << "Hello world!";

	return 0;
}

I can't copy paste the error code so im just retyping it. I apologize.

Debug Assertion Failed!

Program: ...metns\Visual Studio 2008\Projects\Practice\Debug\Practice.exe
File f:\dd\vctools\crt_bld\self_x86\crt\src\fdopen.c
Line 55

Expression: (filedes >= 0 && (unsigned)fildes < (unsigned)_nhandle)

It then mentiosn looking at the visual c++ docmentation.

After i just typed this all out I was looking at the development software and it had a dropdown menu that said debug, and i changed it to an option of release. solved my problem. So that's that I suppose. If anyone knows why I was getting that error in the first place it might save me a headache in the future i suppose. thanks
Last edited by Narue : Dec 16th, 2008 at 11:16 am. Reason: fixed code tags
Reply With Quote  
Posts: 485
Reputation: daviddoria has a spectacular aura about daviddoria has a spectacular aura about daviddoria has a spectacular aura about 
Solved Threads: 31
daviddoria daviddoria is offline Offline
Posting Pro in Training

Re: Debug Assertion failed. help?

  #5  
Dec 16th, 2008
changing to release mode just tells it not to run the assert commands. that is a TERRIBLE idea because now something is going wrong, its just not telling you! It will come back to bite you for sure!

Use step through in debug mode to see which line the assert fails and let us know.

Dave
Reply With Quote  
Posts: 5,126
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 633
Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Debug Assertion failed. help?

  #6  
Dec 16th, 2008
So where's the fdopen() call in your code?

Sure you're not compiling release, then running some ancient debug from some previous project?

When you run the code in debug mode, and get an assert, you should be able to view the stack trace of how you got to that point.
Click on each line of the stack trace until you get to your code. Then figure out what parameter you're passing to the current API call is bad.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
UK Voter? Please send a message to Incapability Brown and the rest of Zanu-Labour
Up to 8Mb PlusNet broadband from only £5.99 a month!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 736 | Replies: 5 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:48 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC