C++ version of search code