im newbees in doing C++ program, now i face a problem where i need to open more than one ".dat" file in a single program. the coding that i use is...

ifstream input;
input.open("Luc.dat");
if (input.fail())
{
cout<<"Unable to open a file \n";
exit(1);
}//end if

while(input>>keyword>>index2)
{//write to Alphabet Array
LUC[x].setkeyword(keyword);
LUC[x].setindex2(index2);
x++;
}//end while
input.close();

it have no problem when i juz use that code to open one file, but when i wana open the second file for example "ltc.dat", at the next process,i use the same method but the system become error.
the error message is ...

Fault: access violation at 0x4013ac; write at address 0x30cb0.

somekind like that........ can anybody help me to solve this problem? im using Borland C++ 5.02 to compile the program.
thanks

Recommended Answers

All 6 Replies

post the code that does not work. After closing the file you should call the clear() method before attempting to open another file with the same fstream object.

Also, it sounds like you're using the old C++ STL libraries. The modern ones don't end in .h, so try using those for a more up-to-date program (probably won't fix your errors, though)

#include <iostream>
#include <fstream>
using namespace std;

yap... the code doesnt work cause i juz post part of it... it is too long to post up all code......

i hv try to clear by using "input.clear();" but still got the same problem, besides that, i canot using the namespace std cause my compiler look like not support it.....

i face the same problem again~~~!!! please help me~ thank Q

i think my LUC array size is big enough, i set it size=1000, and for the x value, i declare it as 0 at the begining of my codding........
i duno y still got that kind of fault but if based on theory, my program can work..........
izzit my compiler problem? Borland C++ 5.02????

>>izzit my compiler problem? Borland C++ 5.02????

Not very likely -- the problem is in your code. But if you don't want to post it then there isn't much anyone here can do for you. You can zip up the project (minus compiler-generated files) and attach to your post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.