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

前端 未结 7 1257

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:39

    The program you posted has an error. I was not able to compile what you posted.

      cout << "Hello Reader.\n"
       << "Welcome to C++.\n"
    

    is not terminated with a semicolon. I added a semicolon and it compiles and runs as you expect.

    Edit: Of course, you have to run the program in a terminal that stays open after the program exits, or use cin to wait for more input, or something like that.

提交回复
热议问题