Problem with reading file

i am trying to load an array with information from a file but i keep getting my message that if cannot open the file. here is the code


string load_array1(string file_name)
{
string x;
string new_array[40];
string line;
x = file_name;
if (x == "spells.txt")
{
fstream open_file ("spells.txt");
cout << "the file is now being located. " << endl;
if (open_file.is_open() == true)
{
cout << "The file is open and found" << endl;
while (! open_file.eof() )
{
getline (open_file,line);
cout << line << endl;
}
open_file.close();
return new_array[40];
}
else
{
cout << "Unable to open file" << endl;
return new_array[40];
}
}
else
{
cout << "See lead programmer" << endl;
return new_array[40];
}


i keep getting an output of "unable to open file"
Maybe you're not in the right directory.

Also, use an ifstream for an input file.
Code tags should be put on that.
Where is your file? Is it in the same dir as the prog? (I believe "\name" is in the root, and "name" is in the dir of the prog. But it might be the other way around. Try both.)
the file "spells.txt" is in the same folder that i am saving this program in. also i used this code on my old computer and it seemed to work then, that was on a xp computer this one is now windows 7 and i cant get it to work.
Last edited on
Try \spells, although I doubt it would work.
yea no dice, argh :(
so that is stupid.....with windows 7 you cant name a file "name.txt" cause it thinks that the .txt is part of the name and not the file type....so it was looking for "spells.txt.txt" thanks for your guys input though :D
Ah. That's the hide known extensions option.
Topic archived. No new replies allowed.