//QT
void ReadTxt()
{
QFile f("result.txt");
if (!f.open(QIODevice::ReadOnly|QIODevice::Text)) //打開指定文件
{
QMessageBox::about(NULL, "文件", "文件打開失敗");
}
QTextStream txtInput(&f);
QString lineStr;
while (!txtInput.atEnd())
{
lineStr = txtInput.readLine(); //讀取數據
qDebug()<<lineStr;
}
f.close();
}
#Python
import os
with open('result.txt', 'r') as f:
lines = f.readlines()
for line in lines:
print(line.rstrip()) #刪除字符串末尾的空白