Hi:
I want open two files, move the contents of the first to the second
after a little work on them. I use fstream. I open both files, one for
reading and the other for reading and writing, first I read from first
file, modify the data and write to the second file. Then I rewind the
second file (No, I don't say rewind(file) I use member seekg)and read
from it for work with the data once them have been formatted to my like.
The problem is that the second file is not created.
If in the while where I read from it I put cout for each line then the
console keeps printing newlines all the time without end; if don't it
passes the while body and then when I use system() for remove the file
it says couldn't remove the file because it doesn't exist.
Below is a sketch of the code. I tried with both orders of opening, and
with the second I proved with ios::in | ios::out and opening first with
out, then closing it and opening again with in.
The question is why does it happen?
I edited the file fstream, but I don't find any exception I could try.
char inName[255], outName[255];
fstream inFile, outFile;
I want read the second again and then delete it, so:
inFile.open(inName, ios::in);
outFile.open(outName, ios::in | ios::out);
while(!inFile.eof()){
inFile.getline(buffer, 255);
outFile << buffer << endl;
}
outFile.seekg(0, ios::beg);
while(!outFile.of()){
outFile.getline(buffer, 255);
cout << buffer << endl;
}
strcpy(buffer, "rm ");
strcat(buffer, outName);
system(buffer);
|