Search⌘ K

File IO of String Data

Explore how to write strings to a file and read them back for display using C++ file input-output streams. Understand the use of getline for reading lines and eof for detecting file end.

Challenge

Write a program to write strings into a file called STRINGS.TXT. Read the same file back and display the contents read on the screen.

Sample run

root@educative:/usr/local/educative# g++ main.cpp 
root@educative:/usr/local/educative# ./a.out

You should be enthusiastic about your future
That is where you are
...