- #1
Saladsamurai
- 3,020
- 7
In a sample code that I have, we use the the following snippet to test whether a file has opened properly:
The exit(1) is confusing me a little bit. I was under the impression that this acts the same way that return(0) does. But upon running it, there are apparently some differences. I am pretty new to this stuff, but it appears that when I use exit(1) the running of the executable does not stop entirely? If I want to run it again, I have to use the 'stop' button first (which implies there is something still running).
Can someone tell me if I am using exit() properly here? Thank you.
Code:
if (inputFile.fail())
{
cerr << "Error opening input file...check that file\n "
"exists and is in current program directory. \n";
[B]exit(1)[/B];
}
The exit(1) is confusing me a little bit. I was under the impression that this acts the same way that return(0) does. But upon running it, there are apparently some differences. I am pretty new to this stuff, but it appears that when I use exit(1) the running of the executable does not stop entirely? If I want to run it again, I have to use the 'stop' button first (which implies there is something still running).
Can someone tell me if I am using exit() properly here? Thank you.