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 6056797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:25:02+00:00 2026-05-23T08:25:02+00:00

i wanna read from file to array of unsigned char in RAD studio 2010,

  • 0

i wanna read from file to array of unsigned char in RAD studio 2010, i have an example,but i need to read to array size of file. Sorry my english

void __fastcall TForm1::ChooseFileClick(TObject *Sender)
{
  TOpenDialog *od = new TOpenDialog(this);
  if (od->Execute()) {
    TFileStream *fs = new TFileStream(od->FileName,fmOpenRead);
    fs->Position = soFromBeginning;
    TMemo *m = new TMemo(this);
    m->Parent = this;
    m->Lines->LoadFromStream(fs);
    delete fs;
    fs = NULL;
  }
  delete od;
  od = NULL;
}
  • 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-23T08:25:02+00:00Added an answer on May 23, 2026 at 8:25 am

    While I’m not sure of your exact intent, I can tell you this: don’t use a raw array!

    In C++, we have the vector type. A vector is very similar to an array, but you can keep adding elements to it. If it gets full, it makes itself bigger. (In actual fact, a vector is simply a wrapper for an array. When it is filled up, it creates a larger array, copies the element to the new array, and then discards the original array).

    When using vector, you’re code follows this style:

    #include <vector> // so we can actually use vectors
    
    ... // program code here
    
    // here's a basic loop which fills a vectors with the numbers 1 to 99.
    std::vector<unsigned char> myVec;
    while( there_is_stuff_to_read )
    {
        myVec.push_back(get_next_element());
    }
    

    Of course, the loop would involve whatever file reading classes you use. The key is the push_back method which adds elements to the vector.

    If other portions of your code rely specifically on using an array of unsigned char, then you can fill the vector, and the use this line of code as necessary:

    unsigned char * arr = &myVec[0];
    

    Then you can use arr as your usual unsigned char array. Just make sure that you don’t hang on this pointer after adding more elements to the vector. It isn’t guaranteed to remain a valid pointer to the start of the vector’s internal array (since the vector reallocates its internal array).

    The previous line of code doesn’t create a whole new array. If you want a genuine copy of the internal contents of the vector, you can use something like:

    unsigned char * arr = new unsigned char[myVec.size()];
    std::copy(myVec.begin(), myVec.end(), arr);
    

    Just make sure you include the standard <algorithm> header.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i wanna read file in an other activity but i made it in another
I have a file and I don't wanna take a copy from this file.
I have read a few posts about what I need but I can't manage
I wanna do read all lines from txt file and I use to it
I wanna read feed entries and I'm just stuck now. Take this for example
i wanna read all the lines from a text so am doing this int
What I wanna do is just accessing to local file system from my iPhone.
The task is to read numbers from file to vector. Format is: one number
I wanna read text between <p></p> tags which comes from database field. I think
I need raw read data from and write data into drive..not via existed filesystem

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.