← All lectures

Lecture 25 · 35 min

File Input & Output

Reading from and writing to files on disk using fstream, ifstream and ofstream — the persistent twin of cin and cout.

fstreamifstream / ofstreamopen / closeReading & writingFile modes
Slide 1 / 16

Why files?

When your program ends, all variables are lost from memory. Files let you:

  • Persist data beyond program execution
  • Share data between different programs
  • Process large datasets that won't fit in variables
  • Log program activity for debugging

Examples: student grade files, game save files, configuration files, logs.

← / → navigateF fullscreenEsc exit⌘K search