qt C++ 替换文件某一行等号之后的内容
发布日期:2021-06-30 10:12:02 浏览次数:3 分类:技术文章

本文共 1562 字,大约阅读时间需要 5 分钟。

方法如下:

将文件中的内容一行一行取出,判断行头是否为等号左值,重写该行添加到字符串,其他不同直接添加到字符串,最后写回到文件。

QString RunFrameNcFile = "/home/。。。";            QFile Ncfile(RunFrameNcFile);            Ncfile.open(QIODevice::ReadOnly);            if (Ncfile.isOpen())            {                QString strtemp;                QTextStream NctextStream(&Ncfile);                QString Xname = "#
="; QString Yname = "#
="; QString Fname = "#
="; QString Alltemp; while(!NctextStream.atEnd()) { strtemp = NctextStream.readLine(); if(strtemp.mid(0,14) == Xname) { Alltemp = Alltemp+ QString("#
= ").toLatin1() + QString::number(MaxXJoint).toLatin1(); Alltemp += QString('\n').toLatin1(); } else if(strtemp.mid(0,14) == Yname) { Alltemp = Alltemp+ QString("#
= ").toLatin1() + QString::number(MaxYJoint).toLatin1(); Alltemp += QString('\n').toLatin1(); } else if(strtemp.mid(0,11) == Fname) { Alltemp = Alltemp+ QString("#
= ").toLatin1() + QString::number(RunFrameSpeed).toLatin1(); Alltemp += QString('\n').toLatin1(); } else { Alltemp += strtemp.toLatin1(); Alltemp += QString('\n').toLatin1(); } } Ncfile.close(); Ncfile.open(QIODevice::WriteOnly); QTextStream in(&Ncfile); in <

转载地址:https://islet.blog.csdn.net/article/details/78689254 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:qt 隐藏tab的一种处理办法
下一篇:qt共享内存方法限制执行一次。

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月25日 18时06分46秒