C++ Programming Tutorial 61 - Reading from Files with ifstream

Поделиться
HTML-код
  • Опубликовано: 19 окт 2024

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

  • @hyrummoses1851
    @hyrummoses1851 4 года назад +27

    I spent a good hour trying to decipher my CS professor's explanation of how to read in files. You explained it perfectly in five minutes. Thank you!!!

  • @abhishekpariyar7895
    @abhishekpariyar7895 4 года назад +40

    Using getline(), how do I read the next name in the file? (In this case, Amy and Susan)
    Edit: I found the solution. Use this ----> while(getline(file, input))

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

    I'm amazed how many videos like this I've watched that still don't show how to read every line in the file to an array. They always stop at just reading the first line. Fortunately I found it in the comments! Still, I've watched a lot of these videos and have learned a lot, thank you!

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

      (I should have said 'vector' instead of array!

  • @nathansayers6409
    @nathansayers6409 3 года назад +2

    so why doesnt it write anything out for me
    i copied line for line what you wrote the only diference was that i used namespace std

  • @chriscruz429
    @chriscruz429 4 года назад +3

    Great video, thanks to these I'm easily passing my CS class.

  • @PunmasterSTP
    @PunmasterSTP 3 года назад +1

    Files? More like miles, and miles of learning! Thanks again so much for making and sharing these wonderful tutorials.

  • @pandorastelevision9442
    @pandorastelevision9442 3 года назад +1

    The explanation is perfect.Keep up the good work hun

  • @vegansynths7757
    @vegansynths7757 4 года назад

    This one has a lot of new info. I get it but will likely need to watch more than once. Very exciting!

  • @nljaded
    @nljaded 3 года назад +1

    Hi, what theme are you using for VS Code?

  • @leonardobernaschina94
    @leonardobernaschina94 4 года назад +1

    Another issue solved thanks to your videos! You're killin it man!

  • @eliaspfeffer
    @eliaspfeffer 3 года назад +1

    what does the for(string name : names) do? Have never seen that before. Thanks in advance! :)

    • @infernocat
      @infernocat 3 года назад +1

      It gets the values of each index in the vector/array opposed to having to do vector[i]

  • @kdtallllll
    @kdtallllll 4 года назад +2

    Hi Caleb, I'm getting some errors on this one and I have the same thing you have; only about halfway through the video so far though. So far I have the while loop and the for loop with all the stuff above, i'm including iostream, string, and vector. I'm getting two problems: "incomplete type is not allowed on std::ifstream file (squiggle is under the word file). And then at while(file >> input) I'm getting "no operator ">>" matches these operands" and I'm compiling using C++11 so I'm not sure what's up. I've tried restarting a few times too.
    Thanks!

  • @katharina1613
    @katharina1613 3 года назад

    You just saved my Life, thank you so much

  • @kyleryxn
    @kyleryxn 4 года назад +2

    why not use namespace std? eliminate the std::

  • @eriksokol4098
    @eriksokol4098 2 года назад

    thank u bro just finished my hw cause of u

  • @gothicknight5538
    @gothicknight5538 3 года назад

    I'm working on an OpenGL project. When I try to use fstream to upload my shader, it returns one line of randomly selected text from the file. Anyone know what's going on?? Thanks.

  • @zengceng
    @zengceng 3 года назад

    how do you filter commas? like a comma separated line, each line must store info into a character or int

  • @maikelgutierrez8558
    @maikelgutierrez8558 4 года назад +2

    Amazing video, thank you a lot!

  • @chadwickcodes6417
    @chadwickcodes6417 3 года назад

    Went back to the getline video after watching this!

  • @nguyentruong3905
    @nguyentruong3905 5 лет назад +3

    for the first tutorial, if I don't use the vector, I use the dynamically-allocated array. How do you do that?

    • @ZNhatAnhZ
      @ZNhatAnhZ 4 года назад

      put every single character from the file to that array

  • @yessinicacio3115
    @yessinicacio3115 2 года назад

    how do i insert the text file to visual studios?

  • @ProfessorElectronic
    @ProfessorElectronic 4 года назад +1

    For me, i cannot type the condition file >> input in the while loop, it gives me an error. It say no operator matchs this operand.

    • @angelosoresi8020
      @angelosoresi8020 3 года назад

      I have the same problem, did you solved it?

    • @angelosoresi8020
      @angelosoresi8020 3 года назад

      i solved, i used std::ofstream file instead of std::ifstream

  • @malaikanazar3600
    @malaikanazar3600 3 года назад

    Can you pls help me design the code which enables us to store the pin ,accountnumber and balance of more than 2 users In file using filehandling concept c++.

  • @johncurrey2387
    @johncurrey2387 2 года назад

    Nice job man!

  • @johnhenry1222
    @johnhenry1222 4 года назад

    How do you print out the second line, please?

  • @neoforce0
    @neoforce0 4 года назад

    Did you leave out "file.close" function? I'm still learning but c++ book had that. the book doesn't offer an active demonstration like video does.

    • @maikelgutierrez8558
      @maikelgutierrez8558 4 года назад

      You should always close the file. Maybe he forgot it but for this video purpose it was great! He is a crack.

    • @hughesd.mungus9819
      @hughesd.mungus9819 3 года назад

      If I'm not mistaken the destructors for file streams take care of that so unless you want to make sure it's closed before the end of the scope you don't need to call 'close'

  • @int4_t
    @int4_t 3 года назад

    Theme?

  • @SweeTsao85
    @SweeTsao85 4 года назад

    ifstream myfile ("Jacob.txt");
    string wholeline;
    while (myfile)
    {
    getline(myfile, wholeline);
    cout

    • @RiuLenn
      @RiuLenn 3 года назад +2

      u need to to put the getline before the while. then add another getline after the cout:
      string wholeline;
      getline(myfile, wholeline);
      while (myfile)
      {
      cout

  • @omerozhan7966
    @omerozhan7966 4 года назад +1

    Thanks for the great work!

  • @the_jones528
    @the_jones528 3 года назад

    What if I ask the user to input the name of the file they want to open, then I put that name inside a variable? How do I then open the file using the variable?

    • @lewisjones284
      @lewisjones284 3 года назад

      0:00 is exactly what you are asking

  • @SuperFireEagle
    @SuperFireEagle 3 года назад

    how would you code it to where it can automatically detect the input file name without hardcoding the name of the file into the program?

    • @gumfvy3340
      @gumfvy3340 3 года назад

      I don't know how to automatically detect the input file name in a directory, and I'm not sure if that's possible, but you can also just make the file name a variable, such as "string filename" and then use cin >> filename; then you open the file using ifstream file (filename)

  • @azamsulaiman4560
    @azamsulaiman4560 4 года назад

    how to get the second or third line only? which mean I only want either Amy or Susan to be display on screen

  • @thejokercrypto8903
    @thejokercrypto8903 3 года назад +1

    anyone using visual studio 2019,
    #include
    #include
    using namespace std;
    int main()
    {
    ifstream reader("file3.txt");
    int a, b;
    if (reader.is_open())
    {
    reader >> a >> b;
    cout

  • @YusuflaOyunZaman
    @YusuflaOyunZaman 2 года назад

    Thanks mister

  • @batman105able
    @batman105able 4 года назад

    How do you load a csv file ?

  • @erawanthewise8227
    @erawanthewise8227 3 года назад

    Amazing video!

  • @ramenra8942
    @ramenra8942 2 года назад

    U saved me a few hours with this lol

  • @guitarhax7412
    @guitarhax7412 5 лет назад +1

    I'M BACK BABY... BOOM

  • @Kim-by5uy
    @Kim-by5uy 2 года назад +1

    If it were a boolean, it would be so true

  • @moistness482
    @moistness482 5 лет назад +1

    the first tutorial has about 30k views while this only has about 1k views. wow

    • @PunmasterSTP
      @PunmasterSTP 3 года назад

      It's 7/28/21 and this video now has over 60k views, and I'm glad about that. It actually has one of the highest view counts out of the videos in this part of the playlist that I've seen so far.

    • @moistness482
      @moistness482 3 года назад +1

      @@PunmasterSTP Quite amazing

    • @PunmasterSTP
      @PunmasterSTP 3 года назад

      @@moistness482 Yeah and I'm hoping this playlist gets even more views over time. I tutor some computer science subjects, one of them being C++, and I try to share links to relevant videos and other resources. I've already linked a few times to this playlist, and I'm planning to continue doing so.

  • @henrydanger4345
    @henrydanger4345 4 года назад

    what IDE is he using in this video?

  • @eliaspfeffer
    @eliaspfeffer 3 года назад

    6:06 yeah it would be truuuuuuee :D

  • @fatezero1919
    @fatezero1919 4 года назад +1

    thank you so much bro, greetings from germany :)

  • @Fallkhar
    @Fallkhar 2 года назад

    Nice video

  • @anonanon1604
    @anonanon1604 2 года назад

    using namespace std;

  • @brocklesnarufcchamp1
    @brocklesnarufcchamp1 3 года назад

    Sheesh, file handling is a lot simpler in c

  • @danielesquivel3155
    @danielesquivel3155 2 года назад

    3:12 "tacos" es racista

  • @Christian-mn8dh
    @Christian-mn8dh 3 года назад

    not working

  • @hansdietrich83
    @hansdietrich83 4 года назад

    Jesus thats zoomed in

  • @jm10oct
    @jm10oct 3 года назад

    gg