Buckys C++ Programming Tutorials - 67 - Reading Custom File Structures

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

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

  • @raoul877
    @raoul877 4 ปีที่แล้ว +74

    It is 2020 now and Man !! You did explain to me what none of my professors where able to show in lectures

    • @bob-ny6kn
      @bob-ny6kn 2 ปีที่แล้ว

      Na. You were not paying attention.

    • @jrippee05
      @jrippee05 2 ปีที่แล้ว

      Raoul, yes, I agree many professors can't explain this correctly.

    • @HamzaKhan-wu6um
      @HamzaKhan-wu6um 2 ปีที่แล้ว +2

      about 2023 :).

    • @buak809
      @buak809 ปีที่แล้ว +5

      @@bob-ny6kn most professors explain most basic shit and when it comes to laboratories/exercises they ask you to do something that they didn't even say a fucking word about

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

      2024

  • @ArthurSilveira
    @ArthurSilveira 9 ปีที่แล้ว +40

    Dude, your tutorial helped me so much, it's hard to find good, to the point information on this topic. I looked for a while before arriving here and you made it ridiculously simple.
    Thanks a lot, keep up the awesome work, I'll subscribe for this.

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

    Nice lesson. I used to do it with other more intricate code lines but this just surprised me with simplicity! Thanks!

  • @jdporter08
    @jdporter08 9 ปีที่แล้ว +5

    I love your tutorials, Bucky! They've helped me so much in my C++ class this semester. Thank you!

  • @rajasparanjpe3791
    @rajasparanjpe3791 5 ปีที่แล้ว +3

    This is so useful. Thanks so much! Now I can write and parse my own custom file structures!

  • @afamudiikeorah2229
    @afamudiikeorah2229 4 ปีที่แล้ว

    9 years later and you still the goat

  • @tholaalw8647
    @tholaalw8647 11 ปีที่แล้ว +92

    BUCKY .. WE ALL

  • @YoussefMohammedVlogs
    @YoussefMohammedVlogs 3 ปีที่แล้ว

    Wow 10 years later i need this in college u are a life saver

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

    It's 2023 and this is literally an amazing explanation

  • @rain_deer
    @rain_deer 13 ปีที่แล้ว

    You can use the string stream class and getline to fallow a string until the '-' occurs
    string str = "a-b-c-d";
    string wrd;
    stringstream ss (str)
    while ( getline ( ss, word, '-' ) );
    cout

  • @nicoletagg9394
    @nicoletagg9394 11 ปีที่แล้ว

    you'd create a struct, then assign it to an array, then loop through the array and use a line like "inputfile>>MyArray[counter].ID>>MyArray[counter].Mark;" depending on what your struct is called and for, then you can loop through the array to display it to the user.

  • @bensa308
    @bensa308 2 ปีที่แล้ว

    Increible. Has explciado en 10 minutos lo que no me han podido explicar en 30 horas

  • @4345ghee
    @4345ghee 9 ปีที่แล้ว

    goddammit thank you once again bucky. I adjusted this program to process a .csv spreadsheet!
    Your series rock. Keep up the great lessons!

    • @VeronicaJessie
      @VeronicaJessie 6 ปีที่แล้ว

      how do you do that? please share

  • @KobusBeets
    @KobusBeets 10 ปีที่แล้ว +5

    Nice Tutorial. You explain it in simple terms. Thank you.

  • @ilyashevchyk7131
    @ilyashevchyk7131 4 ปีที่แล้ว

    Can't find words how helpfull your video was man, so usefull for filling classes, thanks a lot m8

  • @omgNTB
    @omgNTB 2 ปีที่แล้ว

    Your C++ videos are lifesavers

  • @lonelyjk
    @lonelyjk 11 ปีที่แล้ว

    watching your video is much bettern than any other books,thanks

  • @victoriadathan2675
    @victoriadathan2675 5 ปีที่แล้ว

    Thank you soooo much for this video!!!! It really helped me with a problem I was stuck on for one of my programming labs.

  • @Seiffouri
    @Seiffouri 13 ปีที่แล้ว +6

    Hey Bucky! thanks for your great videos.
    Ok I have a question: what if the separator in our file is not just a simple space? for instance its like this: 1 - Bucky - 18.45 (space dash space)
    in python it's pretty easy, but what about C++?

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

    This was super helpful

  • @muhammadshahryarazhar2571
    @muhammadshahryarazhar2571 6 ปีที่แล้ว

    We can use Global variables for both writing and reading from a file.
    And then use switch statement to choose from writing or reading a file by putting read and write code in different functions.

  • @mr.olorinthemaia
    @mr.olorinthemaia 3 ปีที่แล้ว

    saw the lord of the rings online damn bucky you a true master

  • @LetsTalkBackend
    @LetsTalkBackend 7 ปีที่แล้ว

    Thank You Very Very much
    You made me learn file handling very easily

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

    Thank you for this very useful video!
    Brilliant!

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

    Still the best in 2024.

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

    Amazing! I can actually do things with C++ after watching this.

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

    ur tutorials r justttt Perfect

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

    If you having trouble like me try
    1. spelling txt not text.
    2. put the text file you previously created in the same folder of your reading code.

    • @meranti89
      @meranti89 6 ปีที่แล้ว

      thank you! i tried the second option and finally it worked!

    • @chisomodimmegwa3479
      @chisomodimmegwa3479 5 ปีที่แล้ว

      You the goat for real

  • @ibrahimel-shafie1129
    @ibrahimel-shafie1129 12 ปีที่แล้ว

    say it bucky SAY it!!!!!! the "," sign when working with Exel sheets means insert in a new cell
    you could have saved 1 hour of my precious time searching for it!! :(:(
    Anyways you are still the best by far :P:P:P

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

    You really do a damn god job at your tutorials!

  • @salardelavarqashqai
    @salardelavarqashqai 7 ปีที่แล้ว

    thanks a lot. it was very helpful for me and I got my answer which I couldn't find the solution. I really appreciate it.

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

    It would just be crazy for Bucky to store his C++ Tutorial files in his "C++ Tutorials" folder, rather than his "Watermelon" folder.

  • @AkashAgrawal108
    @AkashAgrawal108 9 ปีที่แล้ว +39

    how can we read comma separated values????

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

      did you find a solution to this ?

    • @tsatsralt9112
      @tsatsralt9112 5 ปีที่แล้ว +9

      @@sm4849 you can create another variable char to store the comma and put it between the main data structure.
      ex)
      int a;
      string b;
      double k;
      char x;
      while(theFile >> a >> x >> b >> x >> k){
      bla2;
      }

    • @sm4849
      @sm4849 5 ปีที่แล้ว +12

      @@tsatsralt9112 I found a better solution to it actually , I used the getline function and added the delimiter "," so it kept reading the values and output them this allowed me to put every data object into exclusive vectors for later as well

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

      @@sm4849 Please show me how you did this

    • @sm4849
      @sm4849 4 ปีที่แล้ว

      @@kawaiionion1022 which part ?

  • @DiegoHernandez-ub8wb
    @DiegoHernandez-ub8wb 2 ปีที่แล้ว

    Helped me so much thank you for this

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

    This is like magic how does it know how to break each line down into the fields

  • @jimba6486
    @jimba6486 3 ปีที่แล้ว

    wow, what a great video. I learned a lot here, thank you.

  • @yumi3088
    @yumi3088 8 ปีที่แล้ว

    I think you might wanna add fstream on the title of this video. :) great tutorial, thanks bucky

  • @thinkingaboutjinchen3165
    @thinkingaboutjinchen3165 8 ปีที่แล้ว +14

    "so you know not making that up" 😂

  • @AbhishekSen
    @AbhishekSen 11 ปีที่แล้ว

    Hey bucky you do not know How Much I love you !!

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

    woohoo so simple. thanks for the video😍

  • @oscarcastanedamunoz
    @oscarcastanedamunoz 9 ปีที่แล้ว

    beautiful. thanks for making my life easier. god bless you

  • @surajvarne3992
    @surajvarne3992 3 ปีที่แล้ว

    Thank you so much BUCKY

  • @imaginewang
    @imaginewang 10 ปีที่แล้ว

    This is what I want to learn. Thank you!

  • @isaiahryman3470
    @isaiahryman3470 5 ปีที่แล้ว

    Bucky saves me again.......... Thanks!

  • @blitzmt
    @blitzmt 11 ปีที่แล้ว

    On Mac OS, you need to enter the folder names too. So if your username is MCFan and your project name is MCProject, you need to replace Bucky's line 7 with ifstream theFile("/Users/MCFan/CodeBlocks/MCProject/players.txt");
    Your Codeblocks path may be different and you may need to change that too though...

  • @preymouth
    @preymouth 13 ปีที่แล้ว

    @TheGgamer21 this is the first one that made me laugh, thumbs up if u agree

  • @tannerh222
    @tannerh222 9 ปีที่แล้ว +22

    How does the program know that there is a space between id, name and money?

    • @RexGalilae
      @RexGalilae 8 ปีที่แล้ว +4

      +Tanner Hibberd
      The space is in the file. Each block of data is seperated from the other by a space or a newline.

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

      +Mohammed Zaid Do you mean C++ omits all spaces and treat strings separated by space as independent strings?

    • @RexGalilae
      @RexGalilae 8 ปีที่แล้ว +5

      GYW
      In this case, I guess he used " *filename* >>" to get an input from the file (been a long time since I watched it, sorry).
      The " *filename* >>" works just like "cin>>" which only inputs one word at a time. If you want to input entire sentences as a single string or an object of a class or struct, you use *filename*.getline command.
      PS. I'm not an expert in C++ and my knowledge has become slightly rusty over time. You might want to ask your professor or a friend. I don't recommend going to stackexchange. It's full of judgemental people who are more concerned with the originality and quality of your questions than answering to the content itself.

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

      Here is a valid-ish answer:
      I believe it has to do with the fact that whenever you use 'cin' to input something in the console and type 2 words with a space between them, the program treats these words as if they are 2 separate inputs. Basically, it is just how c++ is.

    • @fahemzoldyck1729
      @fahemzoldyck1729 7 ปีที่แล้ว

      Do you know how , c++ recognize a newline ? (I wanna loop through all lines , one after another , and each time do a specific computation on the strings(words) found in that line )

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

    old is Gold

  • @jadebejamin641
    @jadebejamin641 3 ปีที่แล้ว

    thank you !!. this helped a lot.

  • @nabilaaziz3446
    @nabilaaziz3446 8 ปีที่แล้ว

    one word to describe you.
    AWESOME :)

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

    what if i have to read a string that includes a space??

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

    great bunch of videos, even just showing how the layout of the data file should be was really useful... not something they show us in uni..

  • @jayp8463
    @jayp8463 6 ปีที่แล้ว

    This was so so useful , ty!

  • @ranjacc
    @ranjacc 12 ปีที่แล้ว

    @wh33l0fd00m That's when you usually use XML or another type where you can find the data using algorithms.

  • @victorceballos9946
    @victorceballos9946 6 ปีที่แล้ว

    Excelente, me sirvio de mucho gracias!!!

  • @phatl123456
    @phatl123456 11 ปีที่แล้ว

    Hi Zectroy,
    It may be due to the non-existence of the file (players.txt) in your working directory. If indeed, this is the case, go ahead and open a notepad and just type (or copy and paste from the previous video file) what was originally in the text file. Proceed to Saving the text file in your working directory and close it. Re-Run the program, it should have the display.

  • @Jozekban
    @Jozekban 13 ปีที่แล้ว +6

    Skillet: I need a hero to save me now !
    Mr. Bucky,: here i am!

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

    Bucky, is the variable name (eg id, name, money) stored in the .txt file? Or else how can it know the first group of text is the id, etc??

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

    My program will only read the first line of the file, I have done it exactly how you demo. help?

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

    Dude!, you rule.. the only tutorial I've found.

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

    why is it that when i run my program nothing is appearing other than the press any key to continue button. I am doing everything like you and it still is not working almost like it can't locate the file or something.

  • @kartikagarwal9339
    @kartikagarwal9339 4 ปีที่แล้ว

    Thanks a lot really helpful

  • @chadmcadams8757
    @chadmcadams8757 8 ปีที่แล้ว

    Subbed for this! Lifesaver!!!

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

    amazing tutorial! I need to do something similar but in java, does it work in java the same way?

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

    i don't understand the whole thing that is written in the while condition. the file is being read, but how does c++ know which is id, which is name and which is money? i mean, isn't it all just a bunch of strings in a text file for c++?

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

      it remembers the order

    • @0mer870
      @0mer870 5 ปีที่แล้ว

      It is reading the file but also we are storing its content inside variables. The same way it knows when you cin them in order with the spaces separating each element.

  • @basyoni95
    @basyoni95 8 ปีที่แล้ว

    I have to say it, my friend you are the best. Thank you SO much

  • @alancabezas1681
    @alancabezas1681 3 ปีที่แล้ว

    u r the best, lov u

  • @volikoto
    @volikoto 8 ปีที่แล้ว +3

    Why does mine doesn't show anything if I run it?

    • @volikoto
      @volikoto 8 ปีที่แล้ว

      Gregor Bučar
      Nope, my error is that my text file data have a comma. :D

    • @FingersBlazin
      @FingersBlazin 7 ปีที่แล้ว

      Ah I forgot to make the file with ID player and money so mine was blank lol

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

    How did that string compile without using the string header?

    • @MikeM-py2hq
      @MikeM-py2hq 9 ปีที่แล้ว

      Edit: watch part 71, it will most likely answer your question.

  • @yoloop93
    @yoloop93 11 ปีที่แล้ว

    he forgot to say that the deconstructor close the file at the end of the program. If you want to do something with this file before the end it's not gonna open it since you close it way at the end of the program.

  • @apostolis.diamantopoulos
    @apostolis.diamantopoulos 9 ปีที่แล้ว +13

    wouldn't it be better to use ".eof" like:
    ...
    while (!theFile.eof()) {
    theFile >> id >> name >> money;
    ....
    }

    • @Darku.Matteru
      @Darku.Matteru 9 ปีที่แล้ว

      Apostolis Kennedy
      hello, its a simple alternative. Both way are OK to go.
      To everyone else, eof means END OF FILE, which means in human language, the loop continues up till the end of file is reached ;)

    • @dragansmoljan7917
      @dragansmoljan7917 9 ปีที่แล้ว

      +Apostolis Kennedy when i use this while loop i get an infinite amount of numbers printing, but when i use the bucky example its working just fine...why?

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

      Yes it is better, i might even suggest doing this:
      while (!theFile.eof()){
      if(theFile >> id >> name >> money;)
      {...}
      else
      {cout

  • @shawnchang2136
    @shawnchang2136 8 ปีที่แล้ว

    thanks man, helped a lot :)

  • @Thegrandvoodoo
    @Thegrandvoodoo 11 ปีที่แล้ว

    I have a problem.I used the ofstream in main just as we did in tutorial 66 but I kept it in main and used the ifstream code in a separate function and invoked it with a if statement in main.My problem is it deletes the content in the players text file everytime I access the ifstream function.

  • @TakingItCasual
    @TakingItCasual 13 ปีที่แล้ว

    @SofiaShapferOfficial It seems you only need those for modifying the file, not reading it.

  • @AhmedHadiPADI_scuba_instructor
    @AhmedHadiPADI_scuba_instructor 9 ปีที่แล้ว

    How about if you wanted to print into another txt. file rather that printing onto the console? how to read a certain column onto a txt. file and onto the console as well?
    thanks

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

    can you make SDL tutorials if you can SDL?

  • @oscarcastanedamunoz
    @oscarcastanedamunoz 9 ปีที่แล้ว

    Hey Bucky. How do you paste a screenshot from the clipboard into a file? Please help

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

    what if you only wanted read all of the variables from the text file, but only display one of the players information?

    • @kimhakkol7199
      @kimhakkol7199 5 ปีที่แล้ว

      have you got the answer? im having this problem now..

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

      @@kimhakkol7199 I guess an option would be creating a class or struct containing all the players information and then when you do the loop reading the file, you instance a new object or struct (depends on what you created before), and store it in a vector of its type with all the information, so later you can access the position of the vector you want (maybe searching by player id or something like that) and obtain the specific data you want to show. Or just looping through the vector and showing only the "name" information of each object, or whatever the information you want to show.

    • @kimhakkol7199
      @kimhakkol7199 5 ปีที่แล้ว

      Stacker Coding thank you so much! Your answer is a great help. ;)

  • @subashchandrapakhrin3537
    @subashchandrapakhrin3537 4 ปีที่แล้ว

    Thank you

  • @benjaminhenry7497
    @benjaminhenry7497 7 ปีที่แล้ว

    Could you use this to write a list of infix equations, then read it into an infix to post-fix conversion algorithm?

  • @himaniverma1355
    @himaniverma1355 2 ปีที่แล้ว

    Hi, can you please tell me how to skip first few lines while reading from a file?

  • @cricket461
    @cricket461 11 ปีที่แล้ว

    how do u take random numbers( about 200 of them) from a text file and read them after opening the text file using while, for or do while loops??

  • @jjjggg2927
    @jjjggg2927 5 ปีที่แล้ว

    awesome video:)

  • @anmariebozick3916
    @anmariebozick3916 9 ปีที่แล้ว

    Thank you!

  • @pranayraju1538
    @pranayraju1538 8 ปีที่แล้ว

    how do you do the same when the text file contains commas (,) instead of space characters ( ) ??

  • @sophiatheresa2658
    @sophiatheresa2658 7 ปีที่แล้ว

    hey, everyone!!! so in line 13, the values are stored?
    so if I want to call the information to find the average of the bank account numbers I can use "double money"

  • @tomerik8516
    @tomerik8516 6 ปีที่แล้ว

    What are you saying, that with ifstream obj we dont need to call the deconstructor, but with ostream we have to? Best regards

  • @vortyx090
    @vortyx090 8 ปีที่แล้ว

    Cool tutorial, ty

  • @Bstone7
    @Bstone7 6 ปีที่แล้ว

    hey bucky!
    if we want to read some text from the file and not the rest.
    like if we are marking attendance and the student wants o view only his attendance from the file. How do we do that?

  • @tienphan8388
    @tienphan8388 6 ปีที่แล้ว

    it ran in error for the operator ">>" and "

  • @TakingItCasual
    @TakingItCasual 13 ปีที่แล้ว

    @LaughingShinoo Watch the earlier tutorials, if the file does not exist it will automatically create it.

  • @Impulse_Photography
    @Impulse_Photography 4 ปีที่แล้ว

    Can I manipulate File Pointer to move it to a new location in the file, as in start from the third row, in your case.

  • @WOOOWOOO2326
    @WOOOWOOO2326 10 ปีที่แล้ว

    How to read an adjacency list from a text file?.The problem i have is each line has a variable input size.

  • @lordofutub
    @lordofutub 6 ปีที่แล้ว

    how do you skip a line and then loop through the rest? xyz files have the annoying property of starting off with the amount of atoms.

  • @MiguelMartinez-yj7yu
    @MiguelMartinez-yj7yu 10 ปีที่แล้ว

    I need help! My function is assigned to read first and last name but is also reading numbers as names and last names.

  • @hrbharry
    @hrbharry 11 ปีที่แล้ว

    Bucky make game tutorials with SFML or Allegro! Its not hard at all once you learn C++

  • @muhammadomer999
    @muhammadomer999 12 ปีที่แล้ว

    Thankyou sooooo Much man

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

    okey, i have some problem, i made software for read and write. every time i write text to file.txt, the old text that i have create is lost, and changed with new text. anyone know how to keep the old text ???

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

      +Farras Fauzan This is normal since it starts writing from the beginning of the file. Watch the tutorial after that and he explains it better.

    • @robertreimann1846
      @robertreimann1846 9 ปีที่แล้ว

      +Farras Fauzan I have the same problem... :D

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

      +Farras Fauzan for that we need to use extra file parameters...
      ex-
      fstream file ;
      file.open("sample.txt" , ios::app)
      now this ios::app means to append the file which means its pointer will be placed at the end of the pre existing file and will allow you to contine your work...
      ios::app also allows to place your pointer anywhere in your file to edit it with help of pointers placer(seekp, seekg)
      ..hope this olves your problem... a little late but i recently completed my cs programming..ehehe

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

      pranav anand If you know that so fucking well, why do you even watch c++ tutorials?? :D

  • @laxminarayanchoudhary939
    @laxminarayanchoudhary939 7 ปีที่แล้ว

    Is destructor in filehandling for object of file in c++ , automatically close the file ?please reply as soon as possible.

  • @nurishahaniakamarudin7417
    @nurishahaniakamarudin7417 7 ปีที่แล้ว

    I have problem when display the data. Someone can you help me? I need help. When display the data , the data display twice .