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

Поделиться
HTML-код
  • Опубликовано: 8 фев 2025
  • 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

Комментарии • 46

  • @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.

  • @FluxSentor
    @FluxSentor Год назад +3

    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 11 месяцев назад

    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

  • @ActiveStat-st2ex
    @ActiveStat-st2ex 6 месяцев назад

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

  • @monaaaaaaaaaaaaaaaa
    @monaaaaaaaaaaaaaaaa Год назад

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

  • @GliderOne-uo2jy
    @GliderOne-uo2jy 7 месяцев назад

    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.

  • @sup4eg
    @sup4eg 2 месяца назад

    dude, the material is realy nice, very usefull, thanks a lot

  • @mkapper9800
    @mkapper9800 10 месяцев назад

    Very nice example and explanation 👍 Thanks!

  • @SaadHussain-op8ps
    @SaadHussain-op8ps 9 месяцев назад

    great teaching sir

  • @corv1njano
    @corv1njano Год назад

    really intersting, great video👍

  • @vaibhavydarshan4293
    @vaibhavydarshan4293 9 месяцев назад

    amazing video!

  • @ravi-w6l1p
    @ravi-w6l1p 12 дней назад

    awesome

  • @germankoga8640
    @germankoga8640 6 месяцев назад

    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

  • @edgardoFuentez
    @edgardoFuentez 4 месяца назад

    this video is way too good

  • @utku9594
    @utku9594 8 месяцев назад

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

  • @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 ?.
      ruclips.net/video/mlB8SU_uzQQ/видео.html

  • @ridamadhikari1042
    @ridamadhikari1042 4 месяца назад

    thanks a lot

  • @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.

  • @eliascvi
    @eliascvi Год назад

    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  Год назад +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 Год назад

      ​@@ProfessorHankStalicaIll try that out, thanks 😃🙏

  • @Layan-gy8ql
    @Layan-gy8ql 9 месяцев назад

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

    • @ProfessorHankStalica
      @ProfessorHankStalica  9 месяцев назад +1

      Write a program to read your binary file.

    • @Layan-gy8ql
      @Layan-gy8ql 9 месяцев назад

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

    • @mr.mister311
      @mr.mister311 8 месяцев назад

      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.

  • @DudeHistory
    @DudeHistory Год назад

    what can we do for a string, please reply

    • @ProfessorHankStalica
      @ProfessorHankStalica  Год назад +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 Год назад

      @@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 Год назад

      @@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 Год назад

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

  • @trump1678
    @trump1678 4 месяца назад

    🤠

  • @xoy5
    @xoy5 5 месяцев назад

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