error opening/reading multiple input files

i don't have much code in this and am getting an error...

The algorithm design calls for opening:

the actual source file "fileMerge_axxxx.cpp" to read from
the header file to read from
and
a copy of the source file to write to

i entered debug statements that you can see in the code to make sure they are opening successfully and I continue to get "error opening inFileHeader"
while the others open successfully.

I'm about 2 years experienced with c++ and I don't understand why I have this problem.

Is there anything that sticks out to anyone?
I cannot see the problem.


ORIGINAL PROBLEM SOLVED
}
Last edited on
As far as I know you can't have a file handle to the file that is already open within in same process.

All you can do with such a file handle is open it and that is as far as you can go.
i thought that might be the case, but it is in fact not.

to test for that i entered
"inFileSource.close();"
in the code right after
inFileSource.open("fileMerge_axxxx.cpp");
so that it wouldn't be "in use" and I'm still getting the same error.
#include "fileMerge_axxxx.h"

You didn't close it here, but maybe I'm wrong in this :)
i decided to open the file using the actual path and that made it work!!
i don't know why...?

my other problem is, when I'm reading from the source file it is not reading anything here is the snippet i am using for that

while (!inFileSource.eof())
{
getline(inFileSource, testString, '\n');
cout << testString << endl;
}


i know this is correct because when i test it using inFileHeader it prints everything to the variable testString and to the screen.

here is the design algorithm I'm supposed to be following, am I not going about this the right way?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
set up two input file streams and one output file stream
            for one input stream, open the source (.cpp) file of this program
            for the other input stream, open the header (.h) file of this program
            for the output stream, open a “copy” source (.cpp) file
            repeat
                        read a line from the source input file
                        if the line matches the “include header file” statement
                                    repeat
                                                read a line from the header input file
                                                write the line that was read to the output file
                                    until at the end of the header input file
                        otherwise
                                    write the line that was read to the output file
            until at the end of the source input file

it looks as if the program is supposed to be reading from the source file itself that is executing, is that possible? am i misinterpreting?
Last edited on
Topic archived. No new replies allowed.