David Cameron has announced he will leave his role as prime minister in the wake of the UK's decision to leave the European Union.