0
Can anyone tell me why the output of this program is just "end"? The file naocompre.txt is in the same directory as the program.
Follows the code:
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main ()
{
string info;
ifstream input("naocompre.txt");
if(input.is_open()) {
while(!input.eof()) {
string info;
getline(input,info);
cout<<info<<endl;
}
}
cout<<"end"<<"\n";
return 0;
}
Contents of naocompre.txt:
NaoCompre Costeira
5
7
4
Maria_Benta 1 800
Juliana_Digito 1 800
Zeca_Mole 3 180
Joao_DeMora 3 180
Would need thresh. See where it is running, where it is jumping, isolate the problem until it reaches the point that indicates the problem. He may not have been able to open the file, or it could be something with the data. Except for not closing the file, which is not a problem in something so simple, I’m not seeing problems in the code. It may have escaped me.
– Maniero
The code doesn’t enter the
if(input.is_open()) { ... }
i.e., the file was not found or cannot be opened (it is not open in another program?).– stderr