Reading and Writing to Files (ifstream and ofstream) - C++ Tutorial 25

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ต.ค. 2024

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

  • @keatodiet
    @keatodiet ปีที่แล้ว +96

    I can't believe the real badger from breaking bad gave up selling meth-amphetamine and decided to teach me how to use the c++ standard library. true hero :)

  • @StarAndAster
    @StarAndAster 10 หลายเดือนก่อน +17

    You explained this so simply and yet so effectively. Singlehandedly saving my course grade here. Thanks lots

  • @devmarboy4045
    @devmarboy4045 ปีที่แล้ว +18

    thanks now i can create some kind of load and save system

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

      Me too lol

  • @ineedzemedic5810
    @ineedzemedic5810 7 หลายเดือนก่อน +6

    I hope you sleep every night with sweet dreams. You explained it better than my professor did.

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

    ⭐Get Visual Assist - calcur.tech/vassist
    C++ TH-cam Playlist - calcur.tech/cpp-playlist

  • @teamlaith2259
    @teamlaith2259 6 หลายเดือนก่อน +1

    I don’t know if it’s me or you over complicated the c++ language this video made me forget c++ xd

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

    loveyouuuu u help me to my problem

  • @abdulsammadsaeed1199
    @abdulsammadsaeed1199 10 หลายเดือนก่อน +3

    Thanks it worked for me.
    But i am kinda confused--> in the while loop u just used "FILE" as a length and u inserted the values in the vector "FOODS" using ""FOOD". How did it entered the values? I am not getting that part.

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

      He didn't use file as the length, he used file >> food. Which evaluates to true so long as there is stuff to fetch from the file. That's what the condition is. it checks to see if you can read from the file, if the check is successful, the while loop iterates, and the push_back() function adds the food item into foods. If it is not successful, we exit the while loop and then the rest of the program continues.

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

      @@abdul4515 Ohhhhh that makes more sense! Thankyou!

  • @PoetryInMotion946
    @PoetryInMotion946 25 วันที่ผ่านมา

    Well explained

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

    Please, do not use string or the bloat amount of libraries except for and . This is about new programmers learning C++.

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

    I never saw someone eat lemons.

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

    Good man.

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

    if anyone can help, after I output something to a file I want to save the file, what do I do?

    • @etho7351
      @etho7351 8 วันที่ผ่านมา

      the file should automatically save when you close it and have the information you outputted to it

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

    lemons

  • @saexpat
    @saexpat 11 หลายเดือนก่อน +1

    How to check if file exists?

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

      check the cpp file

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

      and you will see the txt file beside it

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

    Hi, I just want to create a file in cpp. I will update the contents of the file later. Can anyone share me the code for only creating a file? Sorry, I am actually confused with the C style file handling.

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

      #include
      #include
      int main()
      {
      std::ofstream file("filename.txt"); //change "filename" to whatever name you want.
      file.close();
      }

  • @Austin-cr5zo
    @Austin-cr5zo ปีที่แล้ว

    Say you make this file, and it’s to read names. How would you get the file to sort the names in alphabetical order?

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

      You would probably need to create a function that will alphabetize a bunch of strings, then feed the contents of the file through it. You would probably need to save them to a new file, or find a way to delete the contents of the first file and reupload them to it.

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

      You would have to create your own sorting algorithm and have some form of temporary string storage, as Sara said.

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

    how would I use a function that writes its output as a string to a file

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

      file