C++, Same code won’t work btw CLion & Visual Studio

  c++, clion, visual-studio

I have the following code in VS:

#include <iostream>
#include <fstream>

using namespace std;

int main() {
    ifstream inData;
    int temp;

    inData.open("test_file.txt");

    do {
        inData >> temp;
        cout << temp << " ";
    } while (!(inData.eof()));

    inData.close();


    return 0;
}

test_file.txt contains the following data (it’s a single line):

1 2 3 4 5 6 7 8 9 0 10 11

When I built and ran this in VS, it worked fine. Today, when I tried to run it on CLion, it gives me garbage data. I tried creating a new project from scratch in CLion and copy-pasting just the code in main.cpp, but still gives me random data. And now I’m wasting my Saturday wrestling with my IDE instead of just finishing my homework. Any help?

Source: Windows Questions C++

LEAVE A COMMENT