there is good one line '?:' construction in c++ for such outputs:
std::cout << ( i != string::npos ? "YES" : "NO" ) << std::endl;