The sample project HelloCpp has an exit button in its example. Look at HelloWorldScene.cpp and at the function call back menuCloseCallback (function might vary a bit based on version of cocos2dx you are on)
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
CCMessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
#else
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
#endif
}
For android the answer would be CCDirector::sharedDirector()->end();
Note that I don't think Apple will approve you if your app calls exit(0).