Đang chuẩn bị liên kết để tải về tài liệu:
HandBooks Professional Java-C-Scrip-SQL part 60
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Tham khảo tài liệu 'handbooks professional java-c-scrip-sql part 60', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Calling simply new results in a leak if boost regex_search s m reg Did new match if m 1 .matched std cout The expression new matched n if m 2 .matched std cout The expression delete matched n The preceding program searches the input string for new or delete and reports which one it finds first. By passing an object of type smatch to regex_search we gain access to the details of how the algorithm succeeded. In our expression there are two subexpressions and we can thus get to the subexpression for new by the index 1 of match results. We then hold an instance of sub_match which contains a Boolean member matched that tells us whether the subexpression participated in the match. So given the preceding input running this code would output The expression new matched n . Now you still have some more work to do. You need to continue applying the regular expression to the remainder of the input and to do that you use another overload of regex_search which accepts two iterators denoting the character sequence to search. Because std string is a container it provides iterators. Now for each match you must update the iterator denoting the beginning of the range to refer to the end of the previous match. Finally add two variables to hold the counts for new and delete. Here s the complete program include iostream include string include boost regex.hpp int main Are there equally many occurrences of new and delete boost regex reg new delete boost smatch m std string s Calls to new must be followed by delete. Calling simply new results in a leak int new_counter 0 int delete_counter 0 std string const_iterator it s.begin std string const_iterator end s.end while boost regex_search it end m reg New or delete m 1 .matched new_counter delete_counter it m 0 .second if new_counter delete_counter std cout Leak detected n else std cout Seems ok. n Note that the program always sets the iterator it to m 0 . second. match_results 0 returns a reference to the submatch that matched the whole .