Sep 30, 2009 at 7:50pm UTC
ok so I think my program can't find or create my files? im not sure. can someone please tell me whats wrong with this program
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream infile;
ofstream outfile;
float one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve;
infile.open("C:\\temp.dat");
if (!infile)
{
cout<<"File is not there\n";
exit(0);
}
outfile.open("C:\\tempdata.dat");
if (!outfile)
{
cout<<"File cannot be created\n";
exit(0);
}
infile >> one >> two >> three >> four >> five >> six >> seven >> eight >> nine >> ten >> eleven >> twelve;
outfile << one << endl << two << endl << three << endl << four << endl << five << endl << six << endl << seven << endl << eight << endl << nine << endl << ten << endl << eleven << endl << twelve << endl;
infile.close();
outfile.close();
return 0;
}
it runs without any errors but when i run it it says "file cannot be created. but the file is in my C drive. what's wrong?
Sep 30, 2009 at 9:20pm UTC
Do you have permission to create a file in C:\ ?
Sep 30, 2009 at 9:22pm UTC
yes i do i have admin access
Oct 1, 2009 at 12:35am UTC
What is your OS, crappy vista might not let you access the root. Try putting the files in the same directory as the program.Then use a relative path (remove "C:\\")