Question: I want to put each byte in a char array and rewrite the text file removing the first 100,000 characters.

```
    int fs=0;
    ifstream nm,nm1;

    nm1.open("C:\\Dev-Cpp\\DCS\\Decom\\a.txt");

    if(nm1.is_open())
    {
        nm1.seekg(0, ios::end ); 
        fs = nm1.tellg();

    }
    nm1.close();

    char ss[500000];

    nm.open("C:\\Dev-Cpp\\DCS\\Decom\\a.txt");
    nm.read(ss,fs-1);
    nm.close();

    ofstream om;
    om.open("C:\\Dev-Cpp\\DCS\\Decom\\a.txt");
    for(int i=100000;i<fs-1;i++){
            om >> ss[i];
            }
    om.close();

```

Problem is i can't set the character array to a 5 million size. I tried using vector also

```
    vector <char> ss (5000000); 
    int w=0;

    ifstream in2("C:\\Dev-Cpp\\DCS\\Decom\\a.txt", ios::binary);
    unsigned char c2;
    while( in2.read((char *)&c2, 1) )
    {       
    in2 >> ss[w];
    w++;
    }

```

Over here the size of w is almost half that of fs and a lot of characters are missing.

How to do it ?

Answer: 
In most implementations, `char ss[5000000]` tries allocating on the stack, and the size of the stack is limited as compared to the overall memory size. You can often allocate larger arrays on the heap than on the stack, like this:

```
char *ss = new char [5000000];
// Use ss as usual
delete[] ss; // Do not forget to delete

```

Note that if the file size `fs` is larger than 5000000, you will write past the end of the buffer. You should limit the amount of data that you read:

```
nm.read(ss,min(5000000,fs-1));

```
This part is not correct 

```
while( in2.read((char *)&c2, 1) )
{
    in2 >> ss[w];
    w++;
}

```

bacause you first try to read one character into `c2` and, if that succeeds, read *another* character into `ss[w]`. 

I'm not at all surprised if you lose about half the characters here!