Error reading from file in C ++

0

Can anyone tell me why the output of this program is just being "end"? The file naocompre.txt is in the same directory as the program.

Follow 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;

}

Content from naocompre.txt:

NaoCompre Costeira 
5 
7 
4 
Maria_Benta 1 800 
Juliana_Digito 1 800 
Zeca_Mole 3 180 
Joao_DeMora 3 180 
    
asked by anonymous 14.10.2016 / 02:47

1 answer

0

The program is correct. The problem is in your environment. As commented by @stderr, or the file does not exist, or is in another directory, or has another name, or something.

PS. "On my machine it worked."

    
14.10.2016 / 04:36