Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7061311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:27:31+00:00 2026-05-28T04:27:31+00:00

I want to put each byte in a char array and rewrite the text

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:27:31+00:00Added an answer on May 28, 2026 at 4:27 am

    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));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this contact form and I want to put text inside each
I want to translate each byte from a byte[] into a char , then
I want to put individual JComboBoxes into each cells of a JTable. ie. The
I have numerous byte[] representing pdf's. Each byte array needs to be loaded at
I want to put for each bar from barchart a label to generate a
I want to put images in each pages of my ViewPager (like a book).
I want to put all elements of a String array into a Queue(Of String).
I want to take the path of the local directory and put each directory
I want to put several div s next to each other in one row.
I have some images that I want to put on top of each other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.