相关疑难解决方法(0)

为什么在我包含cin.get()后控制台关闭?

我刚刚开始使用C++ Primer Plus学习C++,但我遇到了其中一个例子的问题.就像我指示的那本书一样,我cin.get()在最后包括了防止控制台自行关闭.但是,在这种情况下,它仍然自行关闭,除非我添加两个cin.get()我不理解的语句.我正在使用Visual Studio Express 2010.

#include <iostream>

int main()
{
    int carrots;

    using namespace std;
    cout << "How many carrots do you have?" << endl;
    cin >> carrots;
    carrots = carrots + 2;
    cout << "Here are two more. Now you have " << carrots << " carrots.";
    cin.get();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ visual-studio-2010

9
推荐指数
2
解决办法
5672
查看次数

标签 统计

c++ ×1

visual-studio-2010 ×1