#include#include int main() { QFile file("output.txt"); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream out(&file); out << "Hello, world!\n"; out << "This is a line of text.\n"; file.close(); } return 0; }
#includeIn this example, we create a QFile object representing a file named "input.txt". We then open the file for reading and create a QTextStream object that reads from the file. We then read each line of the file using the readLine function and print it using qDebug. Overall, QTextStream is a very useful class for working with text in C++ in a Qt environment. It allows for easy reading and writing of text to different devices and can be used for a wide variety of tasks such as file I/O and string manipulation.#include #include int main() { QFile file("input.txt"); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(&file); QString line = in.readLine(); while (!line.isNull()) { qDebug() << line; line = in.readLine(); } file.close(); } return 0; }