0

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.

0

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

My problem is tyring to use the string in other places. like sprintf. I'm getting the problem where the string is not being accessed
@user1721803 where the string is not being accessed What do you mean?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.