Theorem Benzecri. A closed surface is flat if and only it is euler number is zero.
Goldman, W. Two papers which change my life: Milnor seminal work on flat manifolds and bundles.
p.4 which has a good outline of the proof.
To be more precise, a surface of genus $g>1$ than cannot be endowed with a differentiable metric whose curvature vanishes identically, since it cannot be endowed with a Koszul derivative which is flat, here flat means that the curvature and the torsion form vanish identically, since we know that the torsion form of the Levi-Civita connection vanishes, a differentiable manifold endowed with a flat differentiable metric has a flat structure; i.e it is an affine manifold. It is a well-known theorem that a Riemannian closed flat manifolds are finitely covered by the torus $T^n$, their fundamental groups are crystallographic groups, so again this theorem also implies that the only oriented surface endowed with a flat metric is the torus.
Remark that in the case of dimension 2, Milnor in his paper On the existence of a connection with curvature zero, Comm. Math.
Helv. 32 (1958), 215-223
Milnor has generalized the work of Benzecri, by computing an equality which represents an obstruction for a bundle defined on a surface to be flat.