finish checking exist function in cpp
all necessary functions written in cpp
cpp rewrite