Program Closes after I run it

{SOLVED}
I restarted Visual Studio and it work lol

So I was following along with the course and wrote my code. When I compiled and ran it, it just closes on me. I tried searching online for an answer and I found that by adding " cin.get(); " above " return 0; "it works. However, the text part that should say press any key to continue, is missing, and when I press enter the window closes.

I’m just wondering if there is a way to fix my code so I don’t have to include the extra part, or if not having the “press any key to continue” is going to be an issue.

(Sorry if it looks a bit messy)

My code (without cin.get(); ) :

#include<iostream>

using namespace std;

int main()

{
cout<< “Welcome to Bulls and Cows\n” ;

return 0;

}

My code with the extra part:

#include<iostream>

using namespace std;

int main()

{
cout<< “Welcome to Bulls and Cows\n” ;

    cin.get():
return 0;

}

Are you running the code in the same way as the lectures?

I just restarted my computer and it started working, maybe it was a glitch but its working now thanks for taking the time to help me :).

You can also try to run without debugging by pressing Ctrl+F5 or go to the menu
and select it from there

I know it is already solved but if the same thing happens to someone else and restarting doesn’t help, check project -> properties -> linker -> system -> subsystem -> console -> APPLY…I clicked OK before applying and then wondered why it doesn’t work.

1 Like

richard_l, thanks a lot. I had no problem with the project we are learning here, but I am much further along in the course and decided to start my own program to practice, and the stupid window closed no matter what I did. So I came back to this lecture for an answer, and yours was spot on (better than any help I found on the web).

Just wanted to share a little correction, it’s probably because we are using different versions. But for me, on VS2017, I found it under Debug -> (name of your project) Properties -> Linker -> System -> Subsystem -> Console -> Apply.

Hope this helps someone

Thanks bro, life saver.

Woohh I did use the (using method) (using namespace std;) , and it works just fine as the instructor mentioned in the video ^^^
but the problem is taking the rest if (cout) or anything else we did use is defined somewhere else out there the std :smile:

Privacy & Terms