How to rewrite a letter in a file containing multiple lines in Qt?
-
19-06-2021 - |
Pergunta
I have a file which contains numerous lines each being a sentence in english.
What my program has to do is: I have to change a letter in one of those lines.
File looks like this:
he has wild dreams
he walks into the forest alone
he transforms into a bear
If i have to change the letter 'e' in "the" of the 2nd line, how do i do it in Qt??
Solução
You could read the file line by line (using QFile::readLine()
), and add it to a QStringList.
while (file.canReadLine())
list.append(file.readLine());
Then you could make the changes in the QStringList and output it to the same file.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow