C++ file handling for beginners! The easiest way to read/write into text files!

Sdílet
Vložit
  • čas přidán 13. 07. 2024
  • 📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
    C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book
    Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEb
    🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/
    Experience the power of practical learning, gain career-ready skills, and start building real applications!
    This is a step-by-step course designed to take you from beginner to expert in no time!
    💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
    Use it quickly, because it will be available for a limited time.
    Download Visual Assist here: bit.ly/WT-CB
    I use it to enhance the performance, features, and support for C, C#, and C++ development in Visual Studio.
    Download Ultra Edit here: bit.ly/UE-CB
    It is a powerful, secure text editor designed specifically for programmers.
    Files are used to store data permanently.
    In this video, you'll learn how to read and write into text files using C++.
    In order to work with files, first, include the fstream library.
    Inside this library there are three data types:
    ofstream - used for writing into files
    ifstream - used for reading from files
    fstream - used for both read and write
    In this video, I'm demonstrating the use of fstream object in file handling.
    In order to open a file we use open() function.
    This function receives two parameters: file name and file open mode.
    The modes in which file can be opened are below:
    ios::in - opens the file to read(default for ifstream)
    ios::out - opens the file to write(default for ofstream)
    ios::binary - opens the file in binary mode
    ios::app- opens the file to append new info at the end
    ios::ate - opens and moves the control to the end of the file
    ios::trunc - removes the data in the existing file
    ios::nocreate - opens the file only if it already exists
    ios::noreplace - opens the file only if it doesn't already exist
    We can also combine different modes using symbol |
    For example:
    myFile.open(“saldinaFile.txt”, ios::out | ios::in);
    In this example, we are opening saldinaFile.txt for both writing and reading.
    🎁 Create Modern Apps, 5x faster, with less code, Download FREE C++Builder Trial: bit.ly/CppBuilderFree
    ☕ If you've found my content helpful and would like to support me, you now have the option to buy me a coffee or a cookie! It's a small gesture of gratitude that means a lot to me and helps me keep creating free educational videos for you. Use the link to make a contribution: bit.ly/CodeBeauty_BuyMeACoffee
    However, please don't feel obligated to do so. I appreciate every one of you, and I will continue to share valuable content with you regardless of whether you choose to support me in this way. Thank you for being part of the Code Beauty community! ❤️😇
    Contents:
    00:00 - Intro
    01:02 - Write into a text file using C++
    07:46 - Append to a text file using C++
    10:35 - Read from a text file using C++
    15:56 - Tasks to test your C++ knowledge!
    Task 1. ASCII Table video: bit.ly/asciiTable
    Task 2. Structures video: bit.ly/structuresVideo
    Add me on:
    Instagram 📸 - / truecodebeauty
    Twitter 🐦- / truecodebeauty
  • Věda a technologie

Komentáře • 512

  • @CodeBeauty
    @CodeBeauty  Před 2 lety +50

    📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
    C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book
    Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEbook
    🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/
    Experience the power of practical learning, gain career-ready skills, and start building real applications!
    This is a step-by-step course designed to take you from beginner to expert in no time!
    💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
    Use it quickly, because it will be available for a limited time.

    • @joshuapobal9861
      @joshuapobal9861 Před 2 lety +1

      Thx a lot I think u talented in teaching..

    • @eunicefoo4499
      @eunicefoo4499 Před 2 lety +1

      I love this video so much, it helps me a lots. Thank you😍

    • @sinclairakoto8564
      @sinclairakoto8564 Před 2 lety

      could you do a tutorial on how to delete a row / entry from a file please 🙏☺

    • @cipherion
      @cipherion Před 2 lety

      Code change: void readFileText(std::string myFileChoice) should have been coded as :
      void readFileText(const std::string& myFileChoice) so it isn't a copied string causing a heap allocation and therefore running much slower and taking up more memory.

    • @appiahgideon213
      @appiahgideon213 Před rokem

      thanks for this video, I've learned a lot from it

  • @tigergumby
    @tigergumby Před 3 lety +230

    You described how to do all this in 20 minutes, what my school book took a million pages to describe. (Give or take a few hundred thousand pages.) Thank you!

    • @DizzyMay123
      @DizzyMay123 Před 2 lety +5

      Exactly! Took me ages to try and work this out then I realised why don't I just find a codebeauty video hahaha

    • @jerryp2433
      @jerryp2433 Před rokem +2

      And a few thousand dollars.

  • @klevismema4998
    @klevismema4998 Před 3 lety +102

    Hey I commented in your last video and I said I was going to have a exam in c++ . I managed to get a 10/10 max score, thank you very much for helping me personally it was such a great journey through these series.

    • @CodeBeauty
      @CodeBeauty  Před 3 lety +18

      I remember 🤗
      I'm so happy and proud! 🥳🥳💗

  • @meekosalas1153
    @meekosalas1153 Před 3 lety +57

    Prefect timing, we are dealing with File I/O this week in class

    • @CodeBeauty
      @CodeBeauty  Před 3 lety +8

      It's going to be an easy class for you. 😁😁
      You can read the description of this video for more details. ☺️

    • @DonteTidwell
      @DonteTidwell Před 3 lety

      same here

    • @KwizeraPacifique-xf9dd
      @KwizeraPacifique-xf9dd Před 4 měsíci

      same here , next week.

  • @sinnyx3248
    @sinnyx3248 Před měsícem +1

    explained my 3 lectures from college in 15 mins!! this is so sick because Ive actually understood you better

  • @alphakalo5231
    @alphakalo5231 Před 2 lety +9

    Thank you so much for your dedication put into these videos. They make learning c++ so much easier and enjoyable!

  • @priyanshusaxena7157
    @priyanshusaxena7157 Před 3 lety +100

    My solution for the 1st challenge, converting a story to cipher and deciphering back the code in the console:
    #include
    #include
    #include
    using namespace std;
    int main()
    {
    fstream Myfile;
    // Taking the input string from the user
    string story;
    cout

    • @hbm293
      @hbm293 Před 3 lety +4

      I think you can skip the "Converting the string to character array" part, as a string is basically already a character array (and there are ways to iterate over each character contained in the "string" object, as you also have used, so you could use directly that when you do the "int(...)" cast when writing into your file ).
      Also it's funny that since you concatenate the numbers in the file without any (non-number) separators between each of them, then when you read back your file you need to do the funny calculation.

    • @Ozonised
      @Ozonised Před 3 lety

      Hey just wanted to say thank you :) Your formula for deciphering the text helped me a ton. I was stuck getting my program to decipher the text but thankfully I discovered your comment and so the formula which provided a ton of help :)

    • @tapansonak1431
      @tapansonak1431 Před 2 lety +2

      Hi can anyone explain me the working of the decypher loop. I am not quite getting it. I didn't get the formula
      num = num * 10 + (line [i]- '0');

    • @ahmedassal8710
      @ahmedassal8710 Před 2 lety

      could you explain the formula
      num = num * 10 + (line[i] - '0' );

    • @jiimmyyy4929
      @jiimmyyy4929 Před 2 lety

      Hey bro your code is awesome...Could you explain the calculations for the deciphering pls

  • @bigbro_songz
    @bigbro_songz Před 2 lety +4

    Big Bro
    3 minutes ago
    I just love how you make coding so simple, Saldina. You have a great gift. Keep up the good work👏🏽👏🏽👏🏽

  • @luxis_2295
    @luxis_2295 Před 3 lety +27

    I’ve been having the doubt of how read and write from a file for weeks because my programming professor did not explained as good as you. You were the light that lit the way for me because I needed it for a project. Thank you Saldina!!

    • @CodeBeauty
      @CodeBeauty  Před 3 lety +1

      You're very welcome! Glad I could help! 🥰🥰

    • @edinfific2576
      @edinfific2576 Před 2 lety +2

      In order to explain something, a person needs to have both a good knowledge and understanding of what they're explaining AND an ability to bring that understanding down to a comprehensible level or, in other words, to bridge that gap between deep understanding and no idea about how something works. Many teachers and professors seem to lack either one, two or all of the three qualities above.

  • @alirezasoleimani2524
    @alirezasoleimani2524 Před rokem

    One of the finest C++ Tutorials in CZcams. Keep up the good job...

  • @potatoitis3326
    @potatoitis3326 Před 10 měsíci +9

    Saldina thank you for making this concept easier to understand. You are definitely an inspiration and I hope to be as great at programming just like you someday.

  • @andregrobler4393
    @andregrobler4393 Před 2 lety +1

    Thanks Saldina. Your lectures are excellent and presentation best I have seen on YT.

  • @gavinzengeni1749
    @gavinzengeni1749 Před rokem +1

    Best teacher i ever had.
    Receive my greetings from Mozambique, Maputo.

  • @cac2244
    @cac2244 Před 2 lety +2

    So friggin' refreshing...quick, to the point and extremely clear and logical... Nothing I could get from 200+ hours on various coding courses on Udemy.

  • @chakt2772
    @chakt2772 Před 3 lety +2

    Awesome explanation. Real beauty in teaching coding. Thanks for great work.

  • @asgm1382
    @asgm1382 Před 2 lety +1

    Amazing video as always, thank you for inspiring others to code. Much love from USA :)

  • @zoraizsyed1910
    @zoraizsyed1910 Před 2 lety

    You're so awesome! Thanks to your explanation I was able to get my class project done!

  • @tanayasharma7776
    @tanayasharma7776 Před 2 lety +1

    one of the best channels for learning c++ ,thanks a lot .

  • @Joinwithmeonmyjourney
    @Joinwithmeonmyjourney Před 3 lety +8

    Hi Saldina! Thanks for your great videos. Going to watch them all🙏

    • @CodeBeauty
      @CodeBeauty  Před 3 lety

      That is awesome. You are so welcome! ☺️☺️

  • @dannywijaya9291
    @dannywijaya9291 Před rokem

    THANK YOU SOO MUCH.very comprehensive and easy to understand.been looking on how to read txt file into c++ for the past few days and no one could explain it as well as you.

  • @sehrishzarin2431
    @sehrishzarin2431 Před rokem +2

    my course constructors ignored this chapter even in exams last semester , now that i want to make my own project i realized how important this topic is

  • @user-cn9jr9hd6f
    @user-cn9jr9hd6f Před 10 měsíci

    I recently started to work on a project which is in C++. I literally knows nothing about C++ and came to you channel. You literally saved my work... Please continue doing this! Many thanks!

  • @himanshurajpal7842
    @himanshurajpal7842 Před 3 lety +8

    Saldina is back🎊🎊🎊🎊👌👌👌👌Namaste didi..... You are on time , Wednesday... I respect your discipline..... thankyou didi 👌

    • @CodeBeauty
      @CodeBeauty  Před 3 lety +1

      I try to be disciplined 😁
      Thank you so much! 🙏

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

    Thanks so much I really needed this !!!

  • @mainamburu8036
    @mainamburu8036 Před rokem +1

    absolutely beautiful ...finally understood file handling

  • @guillermo5295
    @guillermo5295 Před 3 lety +4

    I do really appreciate your time and effort. Thanks a lot for your content! You got the best channel on youtube to learn C++!!!

  • @SILX
    @SILX Před 3 lety +3

    YESSS these tasks are so good!

  • @ghislain7282
    @ghislain7282 Před 3 lety +15

    New video from codeBeauty notification, me on the road running as fast as I can to watch it. Thanks Saldina.

    • @CodeBeauty
      @CodeBeauty  Před 3 lety +1

      You rock! Hope you'll like it! ☺️☺️

    • @ghislain7282
      @ghislain7282 Před 3 lety

      @@CodeBeauty The only thing left is, finishing thoseTasks😊 I’ll always check them.

  • @b0neless437
    @b0neless437 Před rokem

    Saved my life for this assignment, thank you!

  • @theflossydog1825
    @theflossydog1825 Před 2 lety

    Great video, exactly what I needed, thanks!

  • @klasr5837
    @klasr5837 Před 3 lety +4

    Excitedly waiting for your STL playlist... 😀

  • @larrylarragueta368
    @larrylarragueta368 Před 2 lety +3

    I have enjoyed watching you videos. You are truly a good teacher. I have watched C++ file handling, but I would like you to go deeper into file handling with binary files. To be specific, I would like to see you talk about how to copy files in C++ from one place on your hard disk to another. Thank you very much for all of your hard work!

  • @Fox_Gaming208
    @Fox_Gaming208 Před rokem +1

    Most helpfull video EVER MADE! No books or documents or teaches can be compared to this! :D

  • @nidadursunoglu6663
    @nidadursunoglu6663 Před rokem

    normally these videos stress me out but your tone is so calming

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

    Thank you sis, you really helped me!

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

    This has been a great help once again, thank you!

  • @sam-fy3dh
    @sam-fy3dh Před 2 lety +1

    Very Helpfull videos! Understood a lot more, your way of explaining makes things so much easier to understand, would love to see a video about handling other files like json and csv files!

  • @tasharodriguez6881
    @tasharodriguez6881 Před 2 lety +1

    I'm doing Files in class this week so this perfect
    Your truly amazing!! 😍😍😍😍
    Your my favorite coder!!

  • @denisg2000
    @denisg2000 Před 2 lety

    Great video!!! This helped my with my final project. Thank you.

  • @mohamedhazemwwe
    @mohamedhazemwwe Před 3 lety +2

    Thanks for your efforts Saldina! Really instructive content demonstrated simply and briefly.

  • @heikin5562
    @heikin5562 Před 7 měsíci

    Thank you soo much for this.. The explanation was amatuer friendly.. so it was easy to understand

  • @satyaprakash2910
    @satyaprakash2910 Před 3 lety +1

    I am a beginner starting from yesterday. Your videos are so easy to understand. I am going to watch all videos of your channel.
    i started from your beginner's playlist

  • @attila6042
    @attila6042 Před 3 lety

    thank you very much!
    you have been very clear, the method you have shown is also the most "compact" I have foundd

  • @rajashafay2909
    @rajashafay2909 Před 3 lety

    Thank u so much. You really explain it very well . That's make my task more easy to understand.

  • @kingfederico9606
    @kingfederico9606 Před rokem

    That is sweet, only 20 min and everything is clear!

  • @shakeebahmed7246
    @shakeebahmed7246 Před 3 lety

    I always eager to watch your video. Finally I learned the c++ and got a job lately. Thank you so much for your beautifull yet comprehension videos.

    • @CodeBeauty
      @CodeBeauty  Před 3 lety +1

      You got this!
      I'm so proud of you!🥰🥰

  • @quentinarrius
    @quentinarrius Před 3 lety

    excellent clear cut tutorial thank you! :)

  • @abdelfetahissellal5265
    @abdelfetahissellal5265 Před 3 lety +10

    Thanks Sister , for Muslims تقبل الله صيامكم

  • @JordantheComputerScientist

    Thank you so much. You just helped me pass.

  • @FA-lx9qo
    @FA-lx9qo Před 2 měsíci

    That is amazing! Thanks

  • @jamessovea4993
    @jamessovea4993 Před 3 lety

    This was very helpful. Thanks!

  • @animestudent8441
    @animestudent8441 Před 8 měsíci +1

    thanks great video and tutorial

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

    thank you so much, it's so hard to find good answers sometimes even for the simplest of coding questions, you just saved me a lot of headache

  • @freezinghawt
    @freezinghawt Před 2 lety

    AHHHH I LOVE U SO MUCH TY!

  • @rahmasamy7463
    @rahmasamy7463 Před 2 lety +2

    you are my fav at all u are wonderful !!

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

    nice video, helped me a lot before the exam for revision

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

    so helpful !!! thanks

  • @apropo8868
    @apropo8868 Před 5 měsíci +1

    you explain really good and really easy to understand

  • @Islam36073
    @Islam36073 Před 3 lety +5

    I am loving your way of teaching.

  • @SaifulIslam-cq4tm
    @SaifulIslam-cq4tm Před 2 lety

    Great great great video!!!!!!!

  • @bilalcanturan4660
    @bilalcanturan4660 Před rokem

    YOU ARE THE QUEEN

  • @con_el_maestro3544
    @con_el_maestro3544 Před 10 měsíci +1

    I cannot believe that I finally understand this, I'm gonna cry😭. Anyway let me get started with the homework you gave us

  • @scrpld7111
    @scrpld7111 Před 2 lety

    Thank you for you videos CodeBeauty your are my virtual code mentor. Keep up the good work.

  • @user-ip4ih9nb1z
    @user-ip4ih9nb1z Před rokem

    Thank you!! It helped me a lot :)

  • @darylcornelius7762
    @darylcornelius7762 Před 2 lety

    You’re awesome, thank you!

  • @emreserdan4679
    @emreserdan4679 Před rokem

    Very well lesson.I hope,I get high point to exam.Thnx...

  • @samueladjei5466
    @samueladjei5466 Před rokem

    Thank you so much. This was so helpful

  • @user-kr1wc6kk8g
    @user-kr1wc6kk8g Před 3 měsíci +1

    what a capable software engineer you are saldina.confidentialy i can say my teacher .thanks

  • @namehere630
    @namehere630 Před 2 lety

    this is really helpful :) thank you so much :)

  • @fernandomendes4026
    @fernandomendes4026 Před 2 lety +1

    I training my ear for listening the english language by your videos. Thanks.

  • @felipevalles3831
    @felipevalles3831 Před 3 lety

    Excelente vídeo y excelente explicación, aprendido mucho más desde que veo tus vídeos. Saludos desde Lerdo, Durango. Mx.

  • @darklord8793
    @darklord8793 Před 2 lety

    Thank you lady!

  •  Před 3 lety

    your video helps me for better understanding thankuu

  • @Dulge
    @Dulge Před 2 lety

    wow the explanations are on point thanks.

  • @glitch3417
    @glitch3417 Před 3 lety +9

    Thanks Saldina,
    I was waiting for ages for this video.
    Actually I have a request to make, that if you find the time to do so, make an advance level video about file handling like about reading mixed data (numbers, alphabets, symbols, spaces, without new line) and taking out the specific type of data according to our desire and storing it in arrays, and also more info about functions like getline and putting some conditions in their parameters to ignore specific characters.
    Me and my friends will be waiting desperately. 🤞🏻🤞🏻

  • @shortput
    @shortput Před rokem +1

    Great job going through i/o that was helpful.

  • @Mnerd7368_
    @Mnerd7368_ Před 2 lety +1

    Thanks. I have been struggling how to do this for several months.

  • @imadsalem1446
    @imadsalem1446 Před 2 lety

    Thank salinda for all the hard work you put in this channel .i'm imad from syria

  • @babitagurung6724
    @babitagurung6724 Před rokem

    Thank you so much for making this wonderful video. I heavily code in java. I am taking an elective class that requires me to code in C++. I really needed this tutorial.

  • @godfreymukondo6856
    @godfreymukondo6856 Před 2 lety +1

    Very nice you are really a good teacher💯

  • @ANSYoutube
    @ANSYoutube Před 3 lety

    Thanks. Great Explaination👍👏

  • @LukeSkyWarrior
    @LukeSkyWarrior Před rokem +2

    Great video! Much better than some sites explications that use other forms, and I'm not so good listening in english, but she speaks so well and I understand. It deserves my like

  • @kronos336
    @kronos336 Před 2 lety +1

    TY, very useful u are the best.

  • @rinam8663
    @rinam8663 Před 2 lety

    thank you, great help!

  • @yeiyang8698
    @yeiyang8698 Před 2 lety

    Thanks for teaching : ) . It is useful skill

  • @leo2_1
    @leo2_1 Před 2 lety +1

    well, your video really clear, thank you for your video

  • @its_zubby4414
    @its_zubby4414 Před 2 lety

    very well explained !!!!

  • @massfusion
    @massfusion Před 2 lety

    a life saver no cap

  • @GRHAMNTSHANGASE-dw3gu
    @GRHAMNTSHANGASE-dw3gu Před rokem +1

    Hi everyone I'm new to c++ programming .I'm happy with the explanation here I'm just following n typing ,I must say this is awesome thanx for the information

  • @omarbenamer9985
    @omarbenamer9985 Před 2 lety +1

    IT HAS BEEN DAYS OF HARDWORK THAT I PASSED THROUGH IN ORDER TO GET MY FIRST APPLICATION, WHICH IS CONCERNED TO BE THE END OF THE YEAR FINAL PROJECT
    BY YOUR ENLIGHTENMENT; YOU MAKE ME SO HAPPY BECAUSE I COULD SOLVE MANY PROBLEMS THAT I FACED WITH FILES

    • @CodeBeauty
      @CodeBeauty  Před 2 lety

      I'm happy that I was able to help! Great job on your side as well! 🥰🥰

  • @Dir_GAMA
    @Dir_GAMA Před 2 lety

    thanks a lot. this is so helpful.

  • @sanamehdi7284
    @sanamehdi7284 Před rokem

    All that I can say is thank you very much Saldina.

  • @ksanavengsar4050
    @ksanavengsar4050 Před rokem +1

    thank you very very much)))

  • @EveryThing-zj1us
    @EveryThing-zj1us Před 2 lety +1

    Thank you pretty much, This video makes me feel happy.

  • @timyrasegty7857
    @timyrasegty7857 Před 3 lety +9

    It's magnificent!

  • @samialsharari4771
    @samialsharari4771 Před 2 lety

    Thank you so much , I love that

  • @lilyvmax6642
    @lilyvmax6642 Před 2 lety +1

    Thank you comrade

  • @kibromhs7566
    @kibromhs7566 Před 2 lety

    I love your content. It would be great if you do a video for the tasks 😊

  • @Gautamkumar-zb8sw
    @Gautamkumar-zb8sw Před 2 lety

    Really amazing explanation 🙏🙏🙏 thnx ma'am

  • @nikithagalla1474
    @nikithagalla1474 Před 3 lety

    Thank u for all vedios very nice explanation