#includeint main() { QBuffer buffer; buffer.open(QIODevice::WriteOnly); QByteArray data("Hello, World!"); buffer.write(data); buffer.close(); qDebug() << buffer.buffer(); return 0; }
#includeIn this example, we create a QBuffer object named buffer and open it for reading and writing, using the `open()` method with `QIODevice::ReadWrite` mode. Then, we open a file named "input.txt" using QFile and read its contents using the `readAll()` method. Finally, we write the contents of the file to the buffer using the `write()` method of buffer, close the file and print the contents of the buffer to the console using qDebug(). Package/Library: Qt C++ library (Qt Core module) - qbuffer.h and qbuffer.cpp files.int main() { QBuffer buffer; buffer.open(QIODevice::ReadWrite); QFile file("input.txt"); if (file.open(QIODevice::ReadOnly)) { buffer.write(file.readAll()); file.close(); } qDebug() << buffer.buffer(); return 0; }