やあみんな私はプロジェクトのコードの一部を書いています、そして私は一つのことに固執しています。これが良いコーダーがいつか自分で理解するものである場合(私は良いものになりたいので、c ++で5週目、これまでのところ良いです...)、その試用版です。ねじ込みますが、私は約30分間デバッグを行っており、「if」ステートメントがループしている理由がわかりません。
入力は次のようになります。
p 11:34 12:45
ここで、pは、完了したかどうかを示します(出力したい場合は、「s」になります。ここでは「end」で表されます)。
const int LIST_SPACE = 1000; // this is outside of the main function
string c; // and is 1000 because of a parameter set by the teacher
string end = "s";
string start = "p";
int temp_start_hour;
int temp_start_min;
int temp_end_hour;
int temp_end_min;
string colon = ":";
int begin_hours[LIST_SPACE];
int begin_min[LIST_SPACE];
int end_hours[LIST_SPACE];
int end_min[LIST_SPACE];
int i = 0;
do {
cin >> c; //where c is a string
if(c != start && c != end)
{
cout << "ERROR IN INPUT";
return 1;
}
if(c != end)
{
cin >> temp_start_hour >> colon >> temp_start_min;
cin >> temp_end_hour >> colon >> temp_end_min;
begin_hours[i] = temp_start_hour;
begin_min[i] = temp_start_min;
end_hours[i] = temp_end_hour;
end_min[i] = temp_end_min;
cout << begin_hours[i]; //I did this to check if it was storing values
i++;
}
}while(c != end); //ending the do-while loop
私は本当にこの人たちと正しい方向に微調整することを感謝します。または、私が見逃している概念に関する一般的なアドバイス。ありがとう!
ちなみに、私が取得し続ける出力は次のとおりです:(これは入力'p 11:34 12:34'用です)
11111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111Segmentation fault (core dumped)