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

前端 未结 4 907
眼角桃花
眼角桃花 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;
    

    Gets an integer input and leaves a new line after pressing enter key.

    cin.ignore();
    

    Place this after getting inputs to avoid the exit of console.

提交回复
热议问题