If a continuous function on $[0,\pi]$ integrates to zero against cosines, it is identically constant 
Let $f(x)$ is Continuous function on $[0,\pi]$,and for $n=1,2,.....,$ the function $f(x)$ has the following property:$$\int_{0}^{\pi}f(x)\cos{(nx)}dx=0.(n=1,2,......)$$
  Proof: $f(x)\equiv C$(C is a constant) on $[0,\pi] .$

In my way of thinking ,applying  Weierstrass Approximation Theorem, I could give the proof $f(x)\equiv C,$but I failed.
who can help me go futher about this ?Any help will be appreciated!
 A: A typical way to prove that a function $f$ is constant is to show that $$\int_0^\pi f(x)g(x)\,dx=0\tag{1}$$ for every function $g\in C[0,\pi]$  with zero mean (i.e., $\int_0^\pi g(x)\,dx=0$). Indeed, if $f(x_1)\ne f(x_2)$, then let $g$ be the function that is zero on most of the interval and has two triangular peaks at $x_1,x_2$: one  positive, one negative. This $g$ satisfies $\int_0^\pi g(x)\,dx=0$ but $(1)$ fails when the peaks are sufficiently narrow. 
As Daniel Fischer noted, there are multiple ways to prove that the condition (1) is implied by 
$$\int_{0}^{\pi}f(x)\cos{(nx)}dx=0,\quad n=1,2,\dots \tag{2}$$
For example, one can use the fact that the cosine system is an orthonormal basis of $L^2[0,\pi]$, and thus excluding $1$ from it leaves us with the orthogonal complement of $1$. 
Alternatively, use thw Stone-Weierstrass theorem to uniformly approximate $g$  by a linear combination of $\cos \pi n x$, $n=0,1,2,\dots$; observe that the coefficient of $\cos 0=1$ is small and therefore can be dropped while maintaining uniform approximation. 
