#include <fstream> #include <iostream> #include <string> using namespace std; int main() { ofstream outfile; outfile.open("afile.dat",ios::out|ios::trunc); string data; for (int i = 0; i < 10;i++) { data = to_string(i); outfile << data << endl; } outfile.close(); ifstream infile; infile.open("afile.dat",ios::in); while (!infile.eof()) { getline(infile,data); cout << data << endl; } infile.close(); return 0; }