(Abridged) We study the rate at which gas accretes onto galaxies and haloes and investigate whether the accreted gas was shocked to high temperatures before reaching a galaxy. For this purpose we use a suite of large cosmological, hydrodynamical simulations from the OWLS project. We improve on previous work by considering a wider range of halo masses and redshifts, by distinguishing accretion onto haloes and galaxies, by including important feedback processes, and by comparing simulations with different physics. The specific rate of gas accretion onto haloes is, like that for dark matter, only weakly dependent on halo mass. For halo masses Mhalo>>10^11 Msun it is relatively insensitive to feedback processes. In contrast, accretion rates onto galaxies are determined by radiative cooling and by outflows driven by supernovae and active galactic nuclei. Galactic winds increase the halo mass at which the central galaxies grow the fastest by about two orders of magnitude to Mhalo~10^12 Msun. Gas accretion is bimodal, with maximum past temperatures either of order the virial temperature or <~10^5 K. The fraction of gas accreted on to haloes in the hot mode is insensitive to feedback and metal-line cooling. It increases with decreasing redshift, but is mostly determined by halo mass, increasing gradually from less than 10% for ~10^11 Msun to greater than 90% at 10^13 Msun. In contrast, for accretion onto galaxies the cold mode is always significant and the relative contributions of the two accretion modes are more sensitive to feedback and metal-line cooling. The majority of stars present in any mass halo at any redshift were formed from gas accreted in the cold mode, although the hot mode contributes typically over 10% for Mhalo>~10^11 Msun. Galaxies, but not necessarily their gaseous haloes, are predominantly fed by gas that did not experience an accretion shock when it entered the host halo.