#include#include int main() { QFile file("example.txt"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return 1; QTextStream in(&file); while (!in.atEnd()) { QString line = in.readLine(); // process line here } file.close(); return 0; }
#includeIn this example, QFile is used to open the file in write-only mode and write data to the file using the `write()` function. The examples shown above are from the Qt library, which is a cross-platform application development framework. Hence, the package library for QFile would be Qt.int main() { QFile file("example.dat"); if (!file.open(QIODevice::WriteOnly)) return 1; // write data to file char data[] = "Hello World!"; file.write(data, sizeof(data)); file.close(); return 0; }