Friday, July 31, 2009

Exit function in C++?

Is there a such thing?????





if(something == 7) {


exit


}





is there something like that???

Exit function in C++?
there is no exit statement in c++


the correct statement for what you are looking to do is break


as in





if(something==7){


break;


}





hope that helps
Reply:Actually, break doesn't exit an if statement. It only works on for, while, or switch statements.





If you're looking to exit the program, you can use the exit() function. If you're just looking to exit the if statement, there's no good way to do that. You could use a goto statement, though that's not recommended.
Reply:do you mean 'break'?
Reply:you are writing a correct C++ code but depending on your code. you might get a error with something like that.
Reply:try the following








if(something == 7) {


break;


}
Reply:There is an exit statement in c++


u need to use a header file called %26lt;stdlib.h%26gt;


and also the coding for it is as follows





if(something == 7) {


exit(something);


}





this works as i tried it out on my comp





oh and by the way the break statement is used to exit the block and by that i mean within { and }

magnolia

No comments:

Post a Comment