Video není dostupné.
Omlouváme se.

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

Sdílet
Vložit
  • čas přidán 12. 08. 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/professorhank
    paypal.me/hankstalica1
    Bitcoin: 177wfkQwzXiC8o2whQMVpSyuWUs95krKYB

Komentáře • 35

  • @tylerdaniels4601
    @tylerdaniels4601 Před rokem +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 Před rokem +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.

  • @ActiveStat-st2ex
    @ActiveStat-st2ex Před 2 dny

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

  • @ShinyMudkipsArmy
    @ShinyMudkipsArmy Před 5 měsíci

    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

  • @monaaaaaaaaaaaaaaaa
    @monaaaaaaaaaaaaaaaa Před rokem

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

  • @corv1njano
    @corv1njano Před 6 měsíci

    really intersting, great video👍

  • @GliderOne-uo2jy
    @GliderOne-uo2jy Před měsícem

    So clear for me. Thank you so much Prof!

  • @SaadHussain-op8ps
    @SaadHussain-op8ps Před 3 měsíci

    great teaching sir

  • @vaibhavydarshan4293
    @vaibhavydarshan4293 Před 3 měsíci

    amazing video!

  • @djamelbgd301
    @djamelbgd301 Před rokem +1

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

  • @mkapper9800
    @mkapper9800 Před 4 měsíci

    Very nice example and explanation 👍 Thanks!

  • @utku9594
    @utku9594 Před 2 měsíci

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

  • @germankoga8640
    @germankoga8640 Před 10 dny

    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

  • @Hayat_8BP
    @Hayat_8BP Před rokem +1

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

    • @ProfessorHankStalica
      @ProfessorHankStalica  Před rokem

      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 ?.
      czcams.com/video/mlB8SU_uzQQ/video.html

  • @eliascvi
    @eliascvi Před 9 měsíci

    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  Před 9 měsíci +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 Před 9 měsíci

      ​@@ProfessorHankStalicaIll try that out, thanks 😃🙏

  • @wuxianggujun979
    @wuxianggujun979 Před rokem +1

    How to customize a binary file format

    • @ProfessorHankStalica
      @ProfessorHankStalica  Před rokem

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

  • @DudeHistory
    @DudeHistory Před 8 měsíci

    what can we do for a string, please reply

    • @ProfessorHankStalica
      @ProfessorHankStalica  Před 8 měsíci +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 Před 8 měsíci

      @@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 Před 8 měsíci

      @@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 Před 8 měsíci

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

  • @Layan-gy8ql
    @Layan-gy8ql Před 3 měsíci

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

    • @ProfessorHankStalica
      @ProfessorHankStalica  Před 3 měsíci +1

      Write a program to read your binary file.

    • @Layan-gy8ql
      @Layan-gy8ql Před 3 měsíci

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

    • @mr.mister311
      @mr.mister311 Před 2 měsíci

      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.