在C++我正在創建一個程序,要求用戶輸入以下格式的日期:MM/DD/YYYY。由於日期是一個int,並且必須是一個int,所以我認爲最合理的方法是將數組放在一行中。有沒有辦法在獲取數組的用戶輸入時忽略char?
所以我創造了這樣的事情......
int dateArray[3];
for (int i=0; i<3; i++)
cin >> dateArray[i];
int month = dateArray[0];
...etc
我的問題是,如果用戶輸入「1980年1月23日」有什麼辦法,我可以忽略/用戶輸入?
謝謝。
[的std :: istream的::忽略()](http://en.cppreference.com/w/cpp/io/basic_istream/ignore) – 2014-11-23 19:08:50
我會怎麼用它在這一範圍內,雖然? – 2014-11-23 19:09:43
鏈接的引用中給出的示例沒有幫助嗎?只需使用「/」而不是「\ n」和只有數字輸入。 – 2014-11-23 19:11:32