C++ line index in text document

Hello

as beginner need your help

I'm trying to make program which can write phrases into the text document, new line below previous, just in original order.

So now if equal line is not exist in text document, I add it to the document. And if equal phrase is exist, program shows it on output. But I want see not this exist (equal to inserted) phrase, but phrase below it in list order, or above depending on index of equal phrase. Question is how to get index for lines, and how to manipulate with it to get other lines through chosen index?

Last edited on
Can you rephrase your question in less words? I am having trouble understanding what you are asking.
Hello, thanks for feedback, edited, hope now is more clear
One way you could do this.

1. Read your file line by line to a string container. (array of strings)
2. Search your array for a word. (keep track of index in a loop)
3. use modulus (even / odd ) property to determine where you newline is inserted.
4. rewrite the string array over you current file.
Last edited on
Topic archived. No new replies allowed.