serial communication problem

the output:

on

off

on

off

Im using the string class because i dont know any better, i only program in php.
I dont know c++ language so i base it on lots of examples.