Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

C++ Programming [10] - File Input (Reading Text Files)

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
9,853
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Apr 19, 2010

In this tutorial I'll show you how to retrieve data from an external txt file and incorporate it into your program in a useful way.

c++ programming cpp tutorial guide file i/o input output append eof fstream string text help quick easy fast lecture class

  • likes, 0 dislikes

Link to this comment:

Share to:

Uploader Comments (MrCppHelp)

  • Hi, I've tried exactly the same thing that you've done in your video but I'm encountering some errors. I modified your program so that it won't input 10 data members of 'string' type from a text file. The program compiles but when i run it, all i see are an infinite number of '0's being outputted. Can you shed some light on this matter? Do i have to make any major changes to the program so it can read 'string' data type?

  • @JonathanCZH Reading it as a "string" is a completely different animal. I'd prefer using char arrays instead. I'll actually make a video on string input since there's some more steps you have to take.

  • Why all c++ examples are in console application????

  • @Gevor92 how else would you want it shown? if you have any ideas for future tutorials just send me an e mail..

  • how do you calculate the average from numbers in an input file (my input file has 15 numbers)

  • @Johnnyboyinthehouse Well since you're using an integer array, add up all the values each time you read a line from the file. When the eof (end of file) is reached, divide it by the value of the counter. The counter should add one (counter++) each time the line is read.

see all

All Comments (20)

Sign In or Sign Up now to post a comment!
  • I'm new to programming - how can I code a program that can access an excel file, instead of a text file, then be able to compare its string or int contents?  Fors instance an excel file would contain some pc names; if one already exist then result of the comparison would come up saying something like "already exists". Thanks -Rob

  • Thanks, good short tutorial.

  • As below would it be possible for you to do a tutorial on using more than one column of data?

  • Hi MrCPPHelp,

    Thanks for the great tutorial.

    I was wondering if you could do a similar video on txt files containing multiple columns of data. Is the procedure to append separate columns to different arrays much different to what you are doing here?

  • thank's$

    

  • 8 students didn't pass the exam?  Shame on them..

  • This was very helpful, now my goal is to read a file into an array like this one but instead all the numbers are in the same line and i have to sort them out. How would you go about doing this. I was thinking of a newline function then bubble sorting them. Any advice would be greatful, Thanks.

  • Hi, I have a question to ask. Do you know how i can delete data that i have written to a text file through the program?

  • @MrCppHelp Hey thanks that would be a real help. I'll be looking forward to your tutorial video.

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more