【发布时间】:2011-06-18 19:01:03
【问题描述】:
我刚刚开始使用 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;
}
【问题讨论】: