Function that will read strings of time from a .srt file and change it

I am working on a very simple program, which will receive the name of a file and a number (how much you want to delay your subtitles for from that file), then save that file as another file with delayed time. My question here is how to write a function that will change the time.

Let's say that the file looks like that:

1
00:00:49,100 --> 00:00:52,515
- Everything in place?
- You shouldn't have replaced me.

2
00:00:52,770 --> 00:00:55,391
I know, but I wanted to take your shift.

3
00:00:55,940 --> 00:00:58,312
You like him, don't you? You like watching him

4
00:00:58,568 --> 00:01:01,569
- Don't be ridicolous!
- We are going to kill him. Understand?

5
00:01:01,822 --> 00:01:04,313
Morpheus believes, that he's The One.


...and so on. I am thinking that I am supposed to make a for loop, read the first number so the function knows where we are, then go to the second line (but how?) where the time is and sum it up with the number I entered at the start. Am I headed in the right direction here? How to make the function know I want to read the time (00:01:04,313) and change it?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace nih{
	struct time{
		int millisecond; //easier to operate with
	};

	std::istream& operator>>(std::istream &in, time &t){
		int h, min, sec, milli;
		in>>h; in.get(); //ignore the ':'
		in>>min; in.get(); //ignore the ':'
		in>>sec; in.get(); //ignore the ',' (note that it uses , instead of .)
		in>>milli;
		t.millisecond = milli + sec*1000 + min*60*1000 + h*60*60*1000;
		return in;
	}
}

int main(){
	nih::time start, end;
	std::string arrow;
	int id;
	//...
	while(std::cin >> id >> start >> arrow >> end){ //stream redirection
		start += offset; //to be implemented
		end += offset;
		std::cout << id << start << arrow << end;

		std::string line;
		while(std::getline(std::cin, line) and not line.empty()) //the dialog ends with a blank line
			std::cout << line << '\n';
	}
}

Last edited on
Topic archived. No new replies allowed.