Native' has exited with code 0 (0x0)

No matter what I try, my console closed too fast with this statement The program '[6360] projectesting1.exe: Native' has exited with code 0 (0x0).
I'm using Microsoft visual c++ 2010 express.
please help here
Hello Andy1222,

If your console window closes to soon read this:

http://www.cplusplus.com/forum/beginner/1988/

When I first started I used this:

1
2
std::cout << "\n\n\n\n Fin Press any key to continue -- > ";
_getch();  //  Waits for a key press. 


but the "_getch()" is not c++11 compliant and several people complained bout it, so I came up with this:

1
2
std::cout << "\n\n\n\n Fin Press any key to continue -- > ";
 while (!_kbhit()) {}  //  Waits for a key press. 


"_kbhit" is found in the "conio.h" header file which you may have to include or it may come as part of another header file that you include.

I have also seen std::cin.get(); used.

Put these lines before the "return 0;" at the end of main.

The fact that the IDE said The program '[6360] projectesting1.exe: Native' has exited with code 0 (0x0). means that the program worked properly and ended with no problem.

Hope that helps,

Andy
Generally the reason why <conio.h> is not recommended is because it is not part of any C++ standard - it doesn't exist at all on non-Windows platforms, and even on windows, different compilers offer varying (or possibly no) levels of support.

However, of the two conio solutions suggested, I'd recommend _getch();.

The alternative, while (!_kbhit()) {} has the disadvantage that it doesn't actually wait. Instead it busily loops again and again until the condition becomes false - and consumes CPU cycles while doing so.

But for a more standards-compliant solution, I'd suggest (as already linked above) the use of ignore();
http://www.cplusplus.com/forum/beginner/1988/#msg7263
Last edited on
Topic archived. No new replies allowed.