Hi, I am a beginner C++ programmer, beginner Mac user. I cannot open text files for my project, so I tried to run a simple program to read data from a file and it doesn't work.
I have tried placing the file with the executable, tried placing it with the project file and even tried using the full path and it doesn't work. I'm using Xcode 4.6 by the way.
Please help.
I have tried placing the file with the executable, tried placing it with the project file and even tried using the full path and it doesn't work. I'm using Xcode 4.6 by the way.
Please help.
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
cout << "opening data1.txt....\n";
ifstream infile("Data1.txt");
int n=0;
if (infile.is_open())
{
while (infile >> n)
{
cout << n;
cout<<"\b";
}
infile.close();
}
else
{
cout<<"ERROR";
}
return 0;
}
Last edited: