how can i read from a file that i call data into the value x
i placed the file in the program file but keep given me
file not found..
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <string>
using namespace std;
double const NUMB=10;
int main ()
{
double x;
ifstream infile;
infile.open("data");
if (!infile.is_open()){
cout<<"NOT OPEN"<<endl;
system ("PAUSE");
exit (1);
}
infile >>x;
while (infile>0){
cout<<x<<endl;
infile>>x;
}
infile.close();
return 0;
}
With Xcode the file named “data” has to be placed in the build products directory. That is, it needs to go in the same place the executable is put by Xcode after building. By default this is not the directory where the source code is. The easiest way to handle this for command line applications like this is just to include the file “data” in your project and then tell Xcode to copy the file to the build products directory whenever it builds. You do this by clicking on the project and then the target you are building. At the top of the target settings go to the “Build Phases”. The last phase should be “Copy Files”. Click “+” in “Copy Files” and select your “data” file, which will be listed as long as you have added it to the project.