Enrol to start learning
Reading is open to everyone. Enrolling is free, and it is what unlocks the audio lessons, practice tests and progress tracking.
13.3.1. Reading and Writing
This section
Practice test
11 questions on this section. Wrong answers show you what to read again.
Sign up to take itWhole chapter
Revision test
Mixed questions from across the chapter. Your answers get marked.
Sign up to take itQuick
Flashcard drill
3 cards from this lesson. Good the night before a test.
Try these first
- 1.
What class is used in C++ to write data to files?
Hint
Looks like output file stream.
- 2.
Which method would you use to read an entire line from a file?
Hint
It helps to read line by line.
- 3.
What is the purpose of the 'ofstream' class?
- For reading from files
- For writing to files
- For annotating files
Hint
Think about what 'out' stands for.
- 4.
True or False: It is necessary to close a file after opening it in C++.
- True
- False
Hint
Remember what happens if you don't close it.
- 5.
Write a program that creates a file, writes some lines of text to it, and then reads those lines back to display on the console.
Hint
Look carefully at how you're writing and then reading the data.
- 6.
Explain what happens if you read from a file that doesn't exist. Write a code snippet to handle this error.
Hint
Think about checking if the file is open before trying to read.
Exercises
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
4 more questions available
Enrol freeQuiz
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting
1 more question available
Enrol freeChallenge Problems
Total Questions
2
Estimated Time
4 min
Passing Score
70%
Instructions
- Read each question carefully
- You can use hints if you need help
- Complete all questions before submitting