[SOLVED] How can I override a text line in txt file.
-
In my txt file has just 3 paths that I can override.
-
Hii
your given code is working right if i remove line 11.
i have doubt on line 11
What is this _directory3 ?
is this same as item1 or item2 ?
if yes How are you getting _directory3 ? -
Then you should just read the file line by line in e.g. a QStringList. Replace the line you modified in the QStringList and then overwrite the content of the original file with the content of the QStringList.
-
Can you show me an example with this?
-
Of reading a file line by line ?
-
No. I don't now how to use QStringList in this case.
-
Then please, take some time to read the documentation of this class.
One way:
@QStringList lines
//open file etc.
while(!steam.atEnd()) {
lines << stram.readLine();
} @There are also other way to do that e.g. using QString::split
-
The solution was simpler than I imagined.
Simply put:
@if(!file3.open(QFile::ReadWrite | QFile::Truncate)){
qDebug() << "could not open file for writing";
return;@ -
With that you don't just change one line like you ask for, you are overwriting everything.
-
Yes, but I also rewrite those who have not been changed.
-
if your problem is solved then make this title as SOLVED by adding [SOLVED] tag before the title.