#includeQFile file("myfile.txt"); file.open(QIODevice::ReadWrite); file.seek(5); // move the pointer to position 5 file.write("Hello"); // overwrite the text at position 5
#includeIn this example, we open a file for reading, move the file pointer to position 10, and then read the next 5 bytes of data from that position. Package library: Qt Overall, QFile is a useful class for working with files in C++. Its pos property allows you to easily manipulate the current position of the file pointer, which can come in handy when reading or writing files.QFile file("myfile.txt"); file.open(QIODevice::ReadOnly); file.seek(10); // move the pointer to position 10 QByteArray data = file.read(5); // read the next 5 bytes