copy from one vector to another

hi I am trying to read text from text file and put it in a vector v1. then I copy text from v1 to another vector v2.
my text file is in this format
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
studentName
Student Name One
FatherName
Father Name of Student One

separator

studentName
Student name Two
FatherName
Father name of Student Two

separator

studentName
Student Name three
FatherName
Father Name of Student three

separator

studentName
Student name four
FatherName
Father name of Student four

so while writing text to v2 from v1 I dont want to write "studentName", FatherName and separator. I do not want to write these because these are my separators. I just want to write student name one, father name of student one and so on.

here is my code so far
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
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
using namespace std;

int main()
{
	vector<string> v1;
	vector<string> v2;
	string line;

	ifstream in("names.txt", ios::in);
	while(!in.eof()) {
		getline(in, line);
		v1.push_back(line);
	}
	//cout << v1.size();
	copy(v1.begin(), v1.end(), v2.begin());
	int ii;
	for(ii = 0; ii < v2.size(); ii++) {
		cout << v2[ii];
	}
	system("pause");
	return 0;
}

while running the above code it also displays this error
1
2
Debug assertion failed
Expression: vector iterator + offset out of range


Please help how can I achieve above solution?
v1 = v2 should do it and then remove what you don't want
Last edited on
Topic archived. No new replies allowed.