grep matching

In the example below, I want to return all g++ commands in my history using grep matching.

$ history 1 | grep g++ 
   1001  g++ main.cpp -o hello
   1002  g++ main.cpp -o hello
   1006  g++ main.cpp -o hello
   1007  g++ main.cpp -o hello
   1009  g++ main.cpp -o hello
   1039  g++ -version
   1040  g++ --version
   1043  history 1 | grep g++
$