打开文件时,使用参数选择打开文件模式
需要导入QFile和qDebug、QString头文件
写入
覆盖写入
1 QFile f("D:\\qtManager.txt"); 2 if(!f.open(QIODevice::WriteOnly | QIODevice::Text)) 3 6 QTextStream txtOutput(&f); 7 QString str = "123"; 8 txtOutput << str << endl; 9 flose();文末写入
1 QFile f("D:\\qtManager.txt"); 2 if(!f.open(QIODevice::ReadWrite | QIODevice::Append)) //以读写且追加的方式写入文本 3 6 QTextStream txtOutput(&f); 7 QString str = "123"; 8 txtOutput << str << endl; 9 flose();读取
1 QFile f("D:\\qtManager.txt"); 2 if(!f.open(QIODevice::ReadOnly | QIODevice::Text)) 3 6 QTextStream txtInput(&f); 7 QString lineStr; 8 while(!txtInput.atEnd()) 9 13 flose();上一篇:Qt bool转QString再转回bool方法
下一篇:安全PLC和普通PLC的区别
Qt









