아래 코드는 제 코드입니다. 내 얼만진에 문제가있어. 입력 파일에서 정수의 마지막 값을 최대 값과 최소값으로 표시합니다. 값. 누군가 제발 내가 뭘 잘못하고 있는지 말해 줄래?파일에서 읽은 정수의 최소값과 최대 값을 표시하는 방법은 무엇입니까?
#include "cstdlib"
#include "iostream"
#include "fstream"
using namespace std;
int main()
{
fstream instream;
ofstream outstream;
instream.open("num.txt");
if(instream.fail())
{
cout<<"The input file failed to open\n";
exit(1);
}
outstream.open("output.txt");
if(outstream.fail())
{
cout<<"The output file failed to open";
exit(1);
}
int next, largest, smallest;
largest = 0;
smallest = 0;
while(instream>>next)
{
largest = next;
smallest = next;
if(largest<next)
{
largest = next;
}
if(smallest>next)
{
smallest = next;
}
}
outstream<<"The largest number is: "<<largest<<endl;
outstream<<"The smallest number is: "<<smallest<<endl;
instream.close();
outstream.close();
return 0;
}
당신이 디버깅 적이 : 어쩌면이에 그 세 줄을 변경? –
또한 서식을 수정하십시오. –
질문에 [서식의 차이점] (http://stackoverflow.com/posts/10993666/revisions)을보십시오. 다음에는 직접 해보십시오. @ jrok, 질문에서 코드를 수정하고 싶지 않을 수도 있습니다. – Bart