我刚刚开始使用C++ Primer Plus学习C++,但是我遇到了其中一个例子。就像本书指示的那样,我在末尾包含了cin.get()
以防止控制台自行关闭。但是,在这种情况下,除非我添加两个我不明白的陈述,否则它本身仍然会关闭。我使用Visual Studio Express的2010为什么控制台在我包含cin.get()之后关闭?
#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;
}
GetChar();可能有帮助 ? –