C++ implementation of "grep"