How to search throughout a ranged filed?

Well what i mean is this: How can i search from start at some point in .txt file and finish that search when the search field range is reached ! (ofc with C++ code solution)
So we have a single .txt file doc. with contain the following [example]
#010102
Bla bla bla text inside
##010102
#010103
Some text inside
##010103

So what a want it c++ solution to solve it like this

User is entering the wanted search range for ex: he is writing 010102 as integer in the program and now the program should open that .txt file document search for that range witch in our .txt file is "Some text inside" and put that text in a array lets name it b[] and store it there. After that done the program should print that array on the screen.
What i struggle with is: finding and putting that wanted range in array then reading that array ...

I'm open for any kind of crazy or not crazy solution.
If u cannot quite understand me just say it will try to explain my problem better...

Thanks for your time reading this ... and have a good day.
Regards, Kristijan
It's actually a very good question. Your file follows a fairly common format where the data is bracketed by two identical strings, or tags, each on their own line.

So, you'll need to use std::getline() to read lines from the file. once you find a line with your tag on it, you know that the next lines you read will be the text you want to see. Start a new loop to read lines, but this time you print them or save them in a vector or something (instead of ignoring them), only stopping when you find a tag that ends the text (which you don't save/print/whatever).

Hope this helps.
1. Get N from user.
2. Read lines until you find #N (or EOF)
3. WHILE read line. IF line is ##N THEN break ELSE append line to V
4. Print V
@Duoas
It's actually a very good question. Your file follows a fairly common format where the data is bracketed by two identical strings, or tags, each on their own line.

So, you'll need to use std::getline() to read lines from the file. once you find a line with your tag on it, you know that the next lines you read will be the text you want to see. Start a new loop to read lines, but this time you print them or save them in a vector or something (instead of ignoring them), only stopping when you find a tag that ends the text (which you don't save/print/whatever).

Hope this helps.

Thanks for your advice, i used getline and fit perfectly with my code witch was already written and used another array to fit my wanted data.

@keskiverto
1. Get N from user.
2. Read lines until you find #N (or EOF)
3. WHILE read line. IF line is ##N THEN break ELSE append line to V
4. Print V
well i used ##N to be the end of the search and print, thanks for your advice as well.


With this 2 advice's i've solved my problem. Thanks again ...

Regards, Kristijan
Topic archived. No new replies allowed.