QFile file("test.txt"); if (file.open(QIODevice::WriteOnly)) { file.putChar('A'); file.putChar('B'); file.putChar('C'); file.close(); }
QFile file("test.txt"); if (file.open(QIODevice::Append)) { file.putChar('\n'); file.putChar('D'); file.putChar('E'); file.putChar('F'); file.close(); }This example opens the "test.txt" file in append mode. The putChar() function is called four times to write a newline character followed by the characters 'D', 'E', and 'F' to the end of the file. Note that the "\n" is necessary to write the string in the new line. Package Library: - Qt library.