0
votes

I am extracting a line of text from a string using regular expressions. I am storing them in a vector 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:

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

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

it displays the contents.

1

1 Answers

1
votes

cout may cache. endl flushes the cache as cout.flush(); Put cout.flush(); after last loop to see what output with it.