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 ?

This looks like a terrible idea! :) char ss[32556]; Why not use std::string instead?

Dave

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();

Sorry. Double-posted. Wrong Click.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.