Let $f$ be continuous on $[0,1]$ and suppose $\int_0^1f(x)x^ndx=0$ for all $n\in\mathbb{N}_0$. Prove that $f=0$.
*Let $\epsilon\geq 0$. By Weierstrass theorem, we can find a polynomial $p(x)$ such that $|p(x)-f(x)|<\epsilon$, $\forall x\in[0,1]$.
Since $\int_0^1 f(x)x^ndx=0$, then $\int_0^1 f(x)p(x)dx=0$ (Why is this true? Could someone help me with details of rewriting it in terms of a polynomial?)
Since $f$ is continuous on $[0,1]$, $f$ is bounded, so assume $|f(x)|\leq M$ on $[0,1]$.
$|\int_0^1 f(x)^2 dx|=|\int_0^1 f(x)(f(x)-p(x))dx|\leq M\times\epsilon\times(1-0)$ so by letting $\epsilon\rightarrow 0$, we can have $\int_0^1 f(x)^2dx=0$. By continuity of $f(x)^2$, we can conclude that $f(x)=0$ therefore.
Seems like as long as the interval is finite, not only we can apply Weierstrass theorem but also after applying that we can have $\int_a^bf(x)^2 dx=0$ for all $a,b\in\mathbb{R}$, right? What about negative domain?
Any polynomial can be written as $p(x) = \displaystyle\sum_{i=0}^n a_ix^i$, where the $a_i$ are the respective coefficients, and $n$ is the degree of the polynomial if $a_n \neq 0$.
Now, if $f$ is as given in the question, $$ \int_0^1 f(x)p(x) = \int_0^1 f(x) \left(\displaystyle\sum_{i=0}^n a_ix^i\right) = \int_{0}^1 \sum_{i=0}^n a_i f(x)x^i = \sum_{i=0}^n a_i\left(\int_0^1 f(x)x^i\right) = 0 $$
Which is simply written as : the integral is linear, so you can inspect the behaviour of monomials to understand the behaviour of polynomials under the integral.
As for the question of finite intervals, and intervals with negative end points, the theorem still holds true, because the Weierstrass theorem still holds true for these intervals. Depending on the proof you have seen for the Weierstrass theorem, you will be able to adapt the proof for the general case. For example, you can scale the Bernstein polynomials appropriately for a general interval, when it is given for $[0,1]$. The rest of this proof is as you have written.