Sequential Files
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
char buffer[256];
fstream myfile;
myfile.open("test2.txt",ios::out | ios::trunc);
if (myfile.is_open())
{
myfile << "This outputting a line.\n";
myfile.close();
}
myfile.open("test.txt",ios::in);
myfile.getline(buffer,100);
cout << "The file contains " << buffer << "\n";
myfile.close();
myfile.open("test.txt",ios::app);
myfile << " Hey this is another line \n";
myfile.close();
myfile.open("test.txt",ios::in);
myfile.getline(buffer,200);
cout << "The file contains " << buffer << "\n";
myfile.close();
return 0;
}
Related examples in the same category