私はC++ Primer Plusを使用してC++を学び始めましたが、その例の1つに問題があります。指示された本のように、最後にコンソールを閉じるのを防ぐためにcin.get()
を含めました。しかし、私が理解していない2つの文を追加しない限り、この例ではそれだけで閉じます。私は、Visual Studio Expressの2010cin.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();役立つかもしれません ? –