0
저는 C++ 용 파일 I/O를 수정하고 있습니다. 는 의견 여기 C++ - 단순 - 중첩 된 while 루프가 종료되지 않습니까?
없이 단말기에 자신의 소스 코드를 출력하는 프로그램을 작성하는 것은 여기에 문while (!inputstream.eof())
{
if(in_comment == false)
{
inputstream.get(temp);
if(temp == '/')
{
inputstream.get(temp1);
if (temp1 == '*')
{
in_comment = true;
}
else
{
inputstream.putback(temp1);
}
}
cout << temp;
}
if(in_comment == true)
{
inputstream.get(temp);
if(temp == '*')
{
inputstream.get(temp);
if (temp == '/')
{
in_comment = false;
}
}
}
}
그리고 만약 그들이 동안 작업하지 않는 작업 문제의 루프이다
while (!inputstream.eof())
{
while(in_comment == false)
{
inputstream.get(temp);
if(temp == '/')
{
inputstream.get(temp1);
if (temp1 == '*')
{
in_comment = true;
break;
}
else
{
inputstream.putback(temp1);
}
}
cout << temp;
}
while(in_comment == true)
{
inputstream.get(temp);
if(temp == '*')
{
inputstream.get(temp);
if (temp == '/')
{
in_comment = false;
}
}
}
}
루프
나는 eof 마커가 프로그램이 외부 while 루프에서 벗어날 것으로 예상했지만, 그렇지는 않았다. 왜 이런거야?
감사
모든 경고와 디버그 정보 ('g ++ -Wall -Wextra -g')로 컴파일하십시오. 그런 다음 ** 디버거를 사용하십시오 ** ('gdb') –
내부가 실행 중일 때 외부가 손상되는 것을 예상 했습니까? 그렇다면 문제가됩니다. 각 루프의 시작 부분에서'! inputstream.eof()'조건 만 검사합니다 : 외부 루프가 처음에 기회가없는 경우에는 확인할 수 없습니다. – Numeri
Basile Starynkevitch는 디버거를 잘 사용하는 법을 배웠습니다. 다양한 시계로 한 줄씩 코드를 실행하면 매우 유용합니다. (IDE를 사용한다면 거의 확실하게 디버거가 있습니다.) – Numeri