please help close console in c++

Hi people, I have a program which I declared as void main{} and when in a function I want it to close the console I inserted return 0; but it keeps getting me an error. What could be the reason? is there any other way which I could close this sort of program with?
regards
orangeapple
Last edited on
It's because a void function doesn't return anything.

Either remove the return or change the function to return an int.
So there is no way of getting out of void? no sort of system(cls) or something similar but which closes instead of just clearing. My concern is that I already finished the program and made all of its documentation. Unlucky me
Last edited on
Well the program will close when it reaches the end of main, denoted by the closing } for that function.
void main is not C++. Your compiler shouldn't let you get away with it.
Thanks very much to you all. I am still new to this coding so thats why I am asking such elementry question. You were really helpful thanks,
regards
OrangeApple
void main is not C++. Your compiler shouldn't let you get away with it.


Not standard C++, no. However, some compilers will still let this go. I think the VS compiler is one of them, which I've got a feeling is being used here.

In the interested of adhering to the correct standards, yes, the best option would be to use an integer returning function for main.
You can return from a function returning void early with return;
You can exit the program regularly from any point in the code with exit(0);
Whether that's a good idea is a different question.
However, none of that changes anything about the fact that main has to return int.
Topic archived. No new replies allowed.