943,083 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2797
  • C++ RSS
Dec 16th, 2008
0

Debug Assertion failed. help?

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
radmaker3 is offline Offline
8 posts
since Dec 2008
Dec 16th, 2008
0

Re: Debug Assertion failed. help?

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.
C++ Syntax (Toggle Plain Text)
  1. char ch = 'a';
  2. assert(ch != 'a') // assertion failure..
  3. //expression is false..
Reputation Points: 47
Solved Threads: 69
Posting Whiz
cikara21 is offline Offline
340 posts
since Jul 2008
Dec 16th, 2008
0

Re: Debug Assertion failed. help?

Post the text of the assertion as well.
Team Colleague
Reputation Points: 5862
Solved Threads: 949
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Dec 16th, 2008
0

Re: Debug Assertion failed. help?

I simplified the code to this and still got the error.
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2.  
  3. using std::cout;
  4.  
  5. int main(){
  6.  
  7. cout << "Hello world!";
  8.  
  9. return 0;
  10. }

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 12:16 pm. Reason: fixed code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
radmaker3 is offline Offline
8 posts
since Dec 2008
Dec 16th, 2008
0

Re: Debug Assertion failed. help?

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
Featured Poster
Reputation Points: 437
Solved Threads: 204
Posting Virtuoso
daviddoria is offline Offline
1,968 posts
since Feb 2008
Dec 16th, 2008
0

Re: Debug Assertion failed. help?

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.
Team Colleague
Reputation Points: 5862
Solved Threads: 949
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Oct 30th, 2010
0
Re: Debug Assertion failed. help?
Reputation Points: 4
Solved Threads: 1
Newbie Poster
shijobaby is offline Offline
14 posts
since Jul 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: debug assertion failed when using vector iterators
Next Thread in C++ Forum Timeline: Debug Assertion Failed!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC