Why is the Console Closing after I've included cin.get()?

前端 未结 4 904
眼角桃花
眼角桃花 2020-12-03 18:13

I\'ve just started learning C++ using C++ Primer Plus but I\'m having trouble with one of the examples. Like the book instructed I included cin.get() at the end

4条回答
  •  悲&欢浪女
    2020-12-03 18:50

    cin >> carrots;
    

    reads an int but leaves a newline behind.

    cin.get();
    

    reads that newline, and the program ends.

提交回复
热议问题