File IO of Numeric and String Data

Understand the file handling of Numeric and String data in C++.

Challenge

Write a program to write numeric and string data into a file called SAMPLE.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 
Z
25
473.14
Hyperbole!
root@educative:/usr/local/educative# cat SAMPLE.TXT
Z
25
473.14
Hyperbole!

Coding exercise

Your job is to write the code for writing and reading to the file in the main( ) function.

Get hands-on with 1200+ tech skills courses.