Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C and Cpp abort function example
01-21-2010, 06:09 AM
Post: #1
C and Cpp abort function example
This is interesting function which you can use to terminate your programs. Syntax of it is very easy :
Code:
abort();
If you need to stop your program whenever, you can use it.
Here is one simple example of how to use it :
Code:
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
  string s;
  cin>>s;
  if (s=="abort")
    abort();
  else
    cout<<"You did't enter abort !"<<endl;
    system("pause");
}
If user enters "abort" program is going to terminate.
That's all.

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
01-21-2010, 12:24 PM
Post: #2
RE: C and Cpp abort function example
you are can just return with a simple number of choice so you can tell how the program exited. Abort doesn't return anything after closing the program
Visit this user's website Find all posts by this user
Quote this message in a reply
01-21-2010, 09:34 PM
Post: #3
RE: C and Cpp abort function example
Yeah you are right return can be used in main() function in C or C++.

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: