次のようなファイルからデータを読み込もうとしています。
1 1 2007 12 31 2006
12 31 2007 1 1 2008
1 3 2006 12 15 2006
2 29 1900 3 1 1900
9 31 2007 10 28 2009
int
値は日付であると想定されているため、1行に2つの日付があるため、関数を使用して3つのグループで読み取ります。ペアの最初の日付でエラーが返された場合は、次の行にスキップしてそこからループを繰り返す必要があります。エラーがなければ、単に次のグループを評価します。エラーのファイルとbool
変数は参照パラメーターとして関数に渡されるため、Get_Date()
関数の外部でそれに応じて変更されます。私は次のようなステートメントを使用ignore()
してみました:break
while (infile) {
Get_Date(infile, inmonth1, inday1, inyear1, is_error);
if (is_error == true){
infile.ignore(100, '\n');
break;
}
if (is_error == false) {
Get_Date(infile, inmonth2, inday2, inyear2, is_error);
if (is_error == false) {
Get_Date(infile, inmonth2, inday2, inyear2, is_error);
other stuff;
}
}
}
これにより、うるう年で 2 月は 29 日しかないため、4 行目で 1 つのエラーが発生した後、プログラム全体が終了します。ブレークは制御を最も近いループに戻すと思っていましたが、そうではないようです。