Here is an example:
ros::NodeHandle nh;
ros::Subscriber scanSub;
scanSub=nh.subscribe<sensor_msgs::LaserScan>("/scan",10,&AutoExp::processLaserScan,this);
You can implement the callback function however you like
void AutoExp::processLaserScan(const sensor_msgs::LaserScan::ConstPtr& scan){
//scan->ranges[] are laser readings
...
}
Whenever a new laser reading is published to the "/scan" topic, your callback function is called, assuming that nothing goes wrong.
You can always use commands like
rostopic info /scan
rosmsg show sensor_msgs/LaserScan
to have a detailed information about the topic and the message type.
If you read the documentation of the message type, it helps a lot. Here is the link to sensor_msgs/LaserScan Message