Assuming you mean for all $ n \geq 0 $ rather than some fixed $ n $, this is true. One possible proof is to first note that since this result holds for all $ n \geq 0 $, for any polynomial function $ p: [a,b] \to \mathbb R $, $ \int_a^b p(x) f(x) dx = 0 $. Using Stone-Weierstrass, we then have that for any continuous function $ g: [a, b] \to \mathbb R $, $ \int_a^b g(x) f(x) dx = 0 $. If $ f $ is itself continuous, then simply take $ g = f $ to conclude. If f is not continuous, then you can only conclude that $ f = 0 $ a.e., so I only know how do to this with Lebesgue integration.
In this case, we use the fact that for a function $ f \in L^1([-\pi, \pi]) $, if every Fourier coefficient $ a_n = \frac{1}{2 \pi} \int_{-\pi}^{\pi} f(x) e^{-inx} dx = 0 $ then $ f = 0 $ a.e. For a reference, this is Theorem 3.1 in chapter 4 of Stein and Shakarchi's Real Analysis. As $ \cos(nx) $ and $ \sin(nx) $ are continuous for all $ n \in \mathbb Z $, and as $ e^{inx} = \cos(nx) + i \sin(nx) $, we have that every Fourier coefficient of $ f $ is 0, so $ f = 0 $ a.e. by the theorem cited.