#include <stream>
#include <iostream>
#include <stream>
#include <iosfwd>
#include <string>
using namespace std;
int main(int argc, const char * argv[]) {
string op = "original";
ifstream file;
file.open("sample.txt");
if(!file) {
cout << "Error: unable to open file." << endl;
}
else {
while(!file.eof()) {
file >> op;
cout << op << endl;
}
}
file.close();
return 0;
}
sample.txt only contains the word five
I run this code in Visual Studio and the output is
five
I run the exact same code(direct copy and paste, and data.txt is added for sure) in Xcode and what gets printed in the command line is
original
The bug I see is that
file >> op
never really worked in Xcode. WHY?