Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I/O Difficulty Opening File

Status
Not open for further replies.

oop94

Programmer
Jun 14, 2005
31
US
I'm having difficulty opening a destination file using an array called "mystring" in the line
instream4.open(mystring);
First, I open an instream file that contains the following:
C078D2A2.DAT
C078D9E4.DAT
I take the first 12 characters from the file and insert them into an array called "mystring." The content of the array "C078D2A2.DAT" is actually the name of a file that I want to open and copy its contents to a newly created file. So, I open the file with the following:
instream4.open(mystring);
Then, I create a new destination file that has the same file name as the source file, but I place the file somewhere else by appending a path to the file name with the following:
char path[28]="h:\\newfolder\\";
strcat(path, mystring);
and finally open the destination file with the following:
outstream4.open(path, ios::app);

After I copy the contents to this newly created outstream file, I close the instream file and the outstream file, clear the array, and begin the process over again by collecting the next 12 characters (C078D9E4.DAT).

The first file copies perfectly, but my problem lies in the opening of the second file ("C078D9E4.DAT"). In fact, the array seems to be perfect (the characters C078D9E4.DAT are inserted into the array "mystring"), but when I try to open the file with
instream4.open(mystring);
it fails to open. I'm fairly sure that my instream and outstream files are closed before they're opened, so I don't know why this second file isn't opening. Any ideas?
 
I had a similar weird problem a while ago, and I didn't solve it.

Try to reduce the number of fstreams you got by REUSING some of them. If you don't have all of them opened at the same time, why not reuse the closed ones instead of making a new one?
 
Actually, I will be re-using my fstreams because when my company uses my program, the number of files to be copied will change. So, I cannot create a definite number of fstreams; I have to re-use my fstreams in a loop to keep on copying files until there are none left.
Fortunately, I was able to solve my problem yesterday. Here is the thread:
It was uolj's suggestion to declare the stream variable inside the loop that solved my problem.
Thank you for your suggestion!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top