search/edit existing ascii-file

I have an ascii-file containing several lines of information.
the file looks something like this:

2345
an integer
line with text
9835
another integer
another line with some text

and so on

i first need to find the respective number (ex 9835), and then manipulate(in this case overwrite) some of the next lines of information.

For example in one case i want to overwrite only the line of text.

the problem for me is this: i cant figure out how to find the right number, and i dont know how to overwrite the correct line since the posts and lines are different lenghts.

how do i search, and how can i manipulate one spesific line when i dont know the size of the different "posts"?

Marius
you can use a fstream object, open the file and keep reading one line at a time and matching it if you need that line.
to read a line you can use getline(fstream, std::string);
it could be something like this:

1
2
3
4
5
6
7
8
9
10
11
while(!fstream::eof())
{
getline(fstream, std::string);
if(std::string == "required number")
{
overwrite_line()
break;
}
}

fstream:close();


you need to think how you overwrite the line.
im gonna change the format of the file im reading from, your post helped alot writeonsharma.

thanks =)
Topic archived. No new replies allowed.