How to use binary files [an updated C++ tutorial]

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.ย. 2024
  • Learn how to use binary files, the difference between binary and text files, the pros and cons of binary files, and some mistakes to avoid.
    In this C++ tutorial for beginners, you'll through example programs using Visual Studio Community.
    // Learn more:
    Check out my playlist on C++ Advanced File Operations:
    • CH12: Advanced File Op...
    // Consider supporting this channel in multiple ways
    ko-fi.com/prof...
    paypal.me/hank...
    Bitcoin: 177wfkQwzXiC8o2whQMVpSyuWUs95krKYB

ความคิดเห็น • 37

  • @tylerdaniels4601
    @tylerdaniels4601 ปีที่แล้ว +7

    I was reverse engineering a binary file and started wondering why everything isn’t just text. The opening minute was a great explanation.
    This was a great help for my reverse engineering project. Now I can think about what data types are probably in the file instead of aimlessly trying to find patterns.

    • @ProfessorHankStalica
      @ProfessorHankStalica  ปีที่แล้ว +1

      Glad you found the video useful. Thanks for the comment!

  • @ActiveStat-st2ex
    @ActiveStat-st2ex 29 วันที่ผ่านมา

    I was gone through the last problem you have mentioned, it was nicely explained, thank you ❤

  • @FluxSentor
    @FluxSentor ปีที่แล้ว +2

    This video conveniently came out near when I am covering it in my own class. Once again, thanks so much for a second take on a topic.

  • @ShinyMudkipsArmy
    @ShinyMudkipsArmy 6 หลายเดือนก่อน

    this was very well explained and quick to understand. i ike how you covered other data types and explained the meaning behind the definitions. saved me a lot of time and stress

  • @GliderOne-uo2jy
    @GliderOne-uo2jy 2 หลายเดือนก่อน

    So clear for me. Thank you so much Prof!

  • @djamelbgd301
    @djamelbgd301 ปีที่แล้ว +1

    How did you make this concept very simple ?? , WOW .
    thank you very much Professor.

  • @monaaaaaaaaaaaaaaaa
    @monaaaaaaaaaaaaaaaa ปีที่แล้ว

    thank you for presenting this in a way that's easy to understand!

  • @mkapper9800
    @mkapper9800 5 หลายเดือนก่อน

    Very nice example and explanation 👍 Thanks!

  • @xoy5
    @xoy5 24 วันที่ผ่านมา

    very good and clean video as a Chili Tomato Noodle student I give u a high five

  • @SaadHussain-op8ps
    @SaadHussain-op8ps 4 หลายเดือนก่อน

    great teaching sir

  • @germankoga8640
    @germankoga8640 หลายเดือนก่อน

    I have a lot of doubts, the first one would be, why are there three objetcs (ifstream,ofstream,fstream)? it did seem like fstream was like the base one and ofstream was text by default, but it seems fstream is also text by default so I don't get the point of ofstream, my other doubt would be, what would the equivalent of fseek be in binary files? also I did understand why you couldn't write the whole array in the function as the sizeof operator returned 8 bytes, what I don't understand is why that wasn't a problem before, also I don't understand why the first argument of the write method has to be of type char* casting pointer types sounds dangerous, also this is not a doubt but more of a wish, since we also saw in this video how to write to text files it would've been cool to see how to read them, another doubt is why when working with textfiles you opened it as a .dat instead of .txt and how did it work anyways, and lastly another comparison to the C function idk why the third argument of how many times to read said number of bytes was removed, it was anyways a great introductory video, but I have all this doubts

  • @utku9594
    @utku9594 3 หลายเดือนก่อน

    I am wondering how Tv image live enhancer program is working.Please explain it.

  • @corv1njano
    @corv1njano 7 หลายเดือนก่อน

    really intersting, great video👍

  • @Hayat_8BP
    @Hayat_8BP ปีที่แล้ว +1

    Please make a tutorial on searching a hex pattern on binary file with (??) and modify it

    • @ProfessorHankStalica
      @ProfessorHankStalica  ปีที่แล้ว

      This video already covers that. Just read in x number of bytes and then you could use bitwise operators to check them or maybe even just hex literals that match the ascii code for ?.
      th-cam.com/video/mlB8SU_uzQQ/w-d-xo.html

  • @vaibhavydarshan4293
    @vaibhavydarshan4293 4 หลายเดือนก่อน

    amazing video!

  • @wuxianggujun979
    @wuxianggujun979 ปีที่แล้ว +1

    How to customize a binary file format

    • @ProfessorHankStalica
      @ProfessorHankStalica  ปีที่แล้ว

      Write to the file in any way needed based on the requirements for your project.

  • @Layan-gy8ql
    @Layan-gy8ql 4 หลายเดือนก่อน

    I’ve a problem, “the file is not displayed in the text editor because it is either binary” what should I do ?

    • @ProfessorHankStalica
      @ProfessorHankStalica  4 หลายเดือนก่อน +1

      Write a program to read your binary file.

    • @Layan-gy8ql
      @Layan-gy8ql 4 หลายเดือนก่อน

      @@ProfessorHankStalica Thanks for help, but how can I ?

    • @mr.mister311
      @mr.mister311 3 หลายเดือนก่อน

      I think you may have misunderstood the point of binary files like this.
      Every file on your computer can either be run (the file is a program) or it needs another program that can read it. Every image file, like a png, needs a program to display the image, for example. If you try to open a png file in VS code, you will probably get the same error message. That is because VS code is a program to display text files, not binary image files.
      If you create your own binary files and you want to display what's inside, you also need to write a program that does that.

  • @eliascvi
    @eliascvi 10 หลายเดือนก่อน

    Hey thanks for the video!, I need help with a project im working on.
    Im trying to write a binary file out of a couple structs I have but I keep getting segment fault errors whenever I read that file, so this is what my structs look like
    struct Synonym {
    std::string name;
    int people;
    Synonym *next;
    };
    struct Antonym {
    std::string name;
    int people;
    Antonym *next;
    };
    struct Word {
    std::string name;
    std::string type;
    std::string desc;
    int people;
    std::string uses;
    Synonym *Synonym_head;
    Antonym *Antonym_head;
    };
    struct Node {
    Word *word;
    Node *next;
    }
    What im trying to write to my binary file is a linked list with those Nodes and I think that whats giving me trouble is using std::strings as they are dynamic and cant be translated that well to binary.
    Ive been reading about serialization but that looks though as fuck to learn lol.

    • @ProfessorHankStalica
      @ProfessorHankStalica  10 หลายเดือนก่อน +1

      You can't save string objects in binary files. You have to use c-strings instead. That's probably what's causing your errors to happen.

    • @eliascvi
      @eliascvi 10 หลายเดือนก่อน

      ​@@ProfessorHankStalicaIll try that out, thanks 😃🙏

  • @DudeHistory
    @DudeHistory 9 หลายเดือนก่อน

    what can we do for a string, please reply

    • @ProfessorHankStalica
      @ProfessorHankStalica  9 หลายเดือนก่อน +1

      If you are talking about a string variable, you have to copy the contents of the variable to an array first. Then store the array to the binary file, as usual.

    • @DudeHistory
      @DudeHistory 9 หลายเดือนก่อน

      @@ProfessorHankStalica got it thanks, but how would you read from it, do we have to create dynamic char array to read as well?

    • @hankstalica1922
      @hankstalica1922 9 หลายเดือนก่อน

      @@DudeHistory The char array doesn't have to be dynamic, but yes, if you want to do the read in one complete operation, you could do the read into a temporary buffer array and then copy the buffer array to the string variable.

    • @DudeHistory
      @DudeHistory 9 หลายเดือนก่อน

      @@hankstalica1922 can u make a video on it please, thanks