-
open input file twice?
if anyone can help, it would be appreciated.
i have opened up a file for input. this input file is then read from byte 1000 til the end, and then a byte count is calculated (x). After this, i have calculated a few other things using the final byte count. i.e. (x - 44).
Then, i have opened up output and written a file header there using the calculations (x - 44).
how do i go about reading the input file again after already having written to output ? I want to start at byte 1000 again, and write from byte 1000 til the end AFTER the header i just wrote in output. I have tried this:
fout.put(char);
but it only seems to work BEFORE i have written to the output file. I can write each byte of the input file before the header, but have had no luck after the header, which i need. is it possible to open the input file twice and get what i need?
any ideas/suggestions?
Thanks,
Keith
-
-
Your post is about as clear as mud. Maybe this example will help:
Code:
#include<string>
#include <fstream>
using namespace std;
int main()
{
ifstream inFile("C:\\TestData\\input.txt");
string text;
inFile>>text;
ofstream outFile("C:\\TestData\\output.txt");
outFile<<text<<endl;
inFile.seekg(0);//sets the input file pointer to 0
inFile>>text;//reads input file again
outFile<<text;
return 0;
}
-
i meant load it into memory, character array or what ever and manipulate/play with it there
make a string/array read the file in. Then instead of going through the file again. Go through the string/array as many times as you wish. Parsing/etc.
If you allocated memory remember to free() it err since this is the C++ board... delete it.
std::string would be the best bet.
Or if you don't like dealing with it in memory (for me its usually easier to do in memory or the on just the first run-through) you can use 7stud's pretty good method.
-LC
-
Thanks, all. this helped mucho!
keith