How to replace a particular text in a file located at any place..?
General and Desktop
4
Posts
3
Posters
3.4k
Views
1
Watching
-
This is my code....I want to replace a text in a file, is this correct can any1 help me...
@
QFile file("E:/qtpro/Abc1.txt");
file.open(QIODevice::ReadWrite | QIODevice::Text);
file.reset();QTextStream fl(&file);
// QTextStream f2(&file);
QString str;str = fl.readLine();
while (!str.isNull()) {
if (str == "Shah") {
//str.replace("Shah",";Shah",Qt::CaseSensitive);
fl<<";Shah"<<str<<"\n";
}
str = fl.readLine();
@[Mark up code, Tobias]
Edit: And again, by André. -
You do not want to write into the file you are reading.
-
Thanx...it worked..