0

I have a file over 100 Kb long. I want to perform operations on successive batches of 256 characters.

int fs=0;
char ss[32556];
ifstream nm,nm1;
nm1.open("as86.txt");
if(nm1.is_open())
{
    nm1.seekg(0, ios::end ); 
    fs = nm1.tellg();
    
}
nm1.close();

nm.open("as86.txt");
nm.read(ss,fs+1);
nm.close();

cout << endl << fs << endl;

ofstream mn;
mn.open("as86.txt");
for(int jm=256;jm<fs;jm++){mn << ss[jm];}
mn.close();

Now i've been reading it using arrays and writing them from the 256th charcter back into the file.I guess arrays can't hold that many values and my text file gets corrupted.

Is there any command in the stream classes to remove the first 256 characters from a file or better array implementation that i can use ?

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by nbaztec
0

better stream classes

stringstream.

better array implementation

vectors.

Other than that. If you just want to omit & read the first 256 chars why not you use:

nm1.open("as86.txt",ios::in|ios::binary);
char arr[257]; //+1 for null
nm.read(arr,256);
while(nm.read(arr,256))
{
   //Read more.
}
nm.close();

Edited by nbaztec: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.