dimanche 17 février 2019

Different output in debug vs in run mode (Reading from a file) c++

I am trying to simply read each line from a file and output it to the console with a cout. However, the result changes depending if i debug it or simply run it. I don't understand why. Also note that the file contains only the sentence outputted to the console when I debug the code.

If you can't see the images this is the code :

int main() {
    ifstream ifs("/Users/manefzahra/CLionProjects/untitled1/workk.txt", ios::in);
    char ligne[256]; // same problem whether i use ifs.getline or getline!
    string s;
    if(!ifs){cout << "not opened";}
    while(getline(ifs,s)) {
        cout << s;
    }
    return 0;
}

Here is the code in the main.cpp

When I simply run the code

When I debug it

Thank you!

Aucun commentaire:

Enregistrer un commentaire