Storing regular expression result in vector<string> using <regex>

I am extracting a line of text from a string using regular expressions. I am storing them in a vector<string> to used later. My problem is when I access the text from the vector nothing comes out. I noticed when displaying the string using cout that it will not display anything unless I used endl after it. I noticed as well that the example given by C++ deliberately cout's endl to display the regex_search result http://www.cplusplus.com/reference/regex/regex_search/.

Here's the snippet of my code in question:

1
2
3
4
5
6
7
8
9
10
11
12
13
while (regex_search(s, m, e)) {
            
     for (auto x:m){
                
        blocks.push_back(x);
     }
            
     s = m.suffix().str();
}

for (auto i: blocks){
        cout << i;
}



When I do

1
2
3
for (auto i: blocks){
        cout << i << endl;
}


it displays the contents.
Last edited on
Topic archived. No new replies allowed.