我試圖從標準輸入讀取。第一行是我要閱讀的行數。接下來我讀的這幾行將再次打印。這裏是代碼:cin.get()在循環中
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
for (unsigned int i = 0; i < n; ++i)
{
char a[10];
cin.get (a, 10);
cout << "String: " << a << endl;
}
return 0;
}
當我運行它,並提供行數,程序退出。我還沒有弄清楚發生了什麼,所以我決定在這裏提問。
在此先感謝。
我不認爲它應該像你說的那樣行爲..再次嘗試。 – 2013-02-27 20:51:21
再次嘗試 - 同樣的錯誤 – 2013-02-27 20:59:17