British Prime Minister David Cameron says he will hold a referendum on leaving the EU if he stays in power.