Read multiple lines from file into string

Hi,

I have a file that contains several paragraphs. Each paragraph starts with a §. Now I want to read all the lines in between two § into a vector<string>. (the § should not be in the vector)
I tried to read the file line by line into the vector and then go through the strings again, and if a string doesn't start with the symbol it's appended to the one before. But this doesn't work... any tipps?


I read the lines using
1
2
3
while(getline(file, line, '\n')){
vector.push_back(line);
}


I also tried reading only the 'good' lines using rfind. but then I didn't know which lines belonged together...
would replacing '\n' by some reg exp do the trick?

my second step constisted of a for loop containing two if statements and different functions on the string, e.g.
1
2
3
4
5
6
for(int a=vector.size();a>0;a--){
if(!vector[a].find("§")){
if(!vector[a-1].find("§")){
vector[a-1]+=vector[a];
}}
}

but this didn't exclude the §-lines..
find() doesn't return a bool, it returns the position of the substring or string::npos if it was not found.
ok, I changed my getline delimiter to '§', now I don't need to append the strings anymore... I only need to get rid off the rest of the § line...
Topic archived. No new replies allowed.