Sequantial or Random Access
By default, the file is sequantial access.
.tellp()
and .tellg()
can tell the current position of the file.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream file("test.txt", ios::in | ios::out);
cout << file.tellp() << endl;
for (int i = 0; i < 10; i++)
{
file << "Line " << i << endl;
cout << file.tellp() << endl;
}