Simulations of the clustering of cold dark matter yield dark-matter halos that have central density cusps, but observations of totally dark-matter dominated dwarf spheroidal galaxies imply that they do not have cuspy central density profiles. We use analytic calculations and numerical modelling to argue that whenever stars form, central density cusps are likely to be erased. Gas that accumulates in the potential well of an initially cuspy dark-matter halo settles into a disc. Eventually the surface density of the gas exceeds the threshold for fragmentation into self-gravitating clouds. The clouds are massive enough to transfer energy to the dark-matter particles via dynamical friction on a short time-scale. The halos central cusp is heated to form a core with central logarithmic density slope gamma=0 before stellar feedback makes its impact. Since star formation is an inefficient process, the clouds are disrupted by feedback when only a small fraction of their mass has been converted to stars, and the dark matter dominates the final mass distribution.