0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by DaWei
One example showed that, but it was AFTER THE RETURN, so it was never executed.
0
wrecker's Avatar, Join Date: Mar 2007
Go4Expert Member
Quote:
Originally Posted by shabbir
Whatever book says is correct but you should be able to see that but it looks like the screen may be just displaying and closing the solution could be to have a cin statement after it.
Code:
#include <iostream.h>

int main()
{
  int i;
  cout << "Hello World!\n";
  return 0;
  cin >>i;
}
I am not a mac expert guy but that could be one of the reason.

Hey Shabbir, the code you works correct. then whats problem???
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by wrecker
Hey Shabbir, the code you works correct. then whats problem???
I also thought so when I posted but then having a statement after the return in main is not a good practice.
0
DaWei's Avatar, Join Date: Dec 2006
Team Leader
Nothing wrong with the code, as code. It's just that the cin is not effective (for keeping the window open). In those instances where the code is running in a window owned by the OS or the IDE and not the program, it isn't going to close until one closes it overtly, anyway.
0
wrecker's Avatar, Join Date: Mar 2007
Go4Expert Member
PLease elaborate that. I was unable to understand...