Hey, everyone! I need to read in a file, modify it, and then output it to another file. Then that file needs to be read in, modified, and then output to yet another file. The problem is that I cannot use the getline() function, because there may or may not be new lines in the 100 MB file. Here is what I have, but it does not work:
The first I/O section adds some characters to the end of the file, and the second ends up being an infinate loop because file_in.tellg() always equals -1. I am really lost, and I have been trying to do this for a few weeks, so any help would be great. Thanks.Code:char * text;
int len, pos, ending;
ifstream file_in ("test.txt");
ofstream file_out ("enc.txt");
pos = 0;
file_in.seekg(0, ios::end);
len = file_in.tellg();
ending = len;
file_in.seekg(pos, ios::beg);
while(len > 0){
if(len > 350){len = 350;}
text = new char[len];
file_in.read(text, len);
//modify text
file_out << text;
pos = file_in.tellg();
file_in.seekg(pos+len, ios::beg);
len = ending - pos;
}
file_in.close();
file_out.close();
file_in.open("enc.txt", ios_base::in);
file_out.open("unenc.txt", ios_base::out);
pos = 0;
file_in.seekg(0, ios::end);
len = file_in.tellg();
ending = len;
file_in.seekg(pos, ios::beg);
while(len > 0){
if(len > 350){len = 350;}
text = new char[len];
file_in.read(text, len);
//modify text
file_out << text;
pos = file_in.tellg();
file_in.seekg(pos+len, ios::beg);
len = ending - pos;
}
file_in.close();
file_out.close();

