very basic C++ program closes after user input for no particular reason?

前端 未结 7 1189

I just started learning C++ and I wrote this sample program from the text and when I compile and run it, it just closes after the user inputs any number and presses enter.

7条回答
  •  后悔当初
    2021-01-18 04:52

    Your program ends right after you print out your text. If you want to see anything on the screen you can add a cin right before your return 0 so your program waits for a user response before exiting.

    // Wait for user to hit enter
    cin >> dummyVar;
    
    return 0;
    

提交回复
热议问题