Integrable function and measure space

I have two similar problem in measure space.

1. let $f$ be an integrable function on a measure space $X,M,\mu$ such that $$\int_{E} f \, d\mu = 0$$for all sets $E \in M$.

2. let $f$ be an integrable function on a measure space $R,L,\lambda$ (that is lebesgue space and measure) such that $$\int_{a}^b f \, d\lambda = 0$$ for all $-\infty<a<b<\infty$.

I wanna prove that $f=0$ $a.e.$ both case

I got an intution that I can using that fact: $$\lambda\left\{x\mid f(x)\geq \frac 1n\right\}\leq n\int f \, d\lambda=0,$$ But, I can't apply that precisely. Could you give some hints?

-
Why can't you apply this inequality? –  Davide Giraudo May 8 '12 at 14:42
Hint: apply your intuition to $f^{+}$ and $f^{-}$. –  Siminore May 8 '12 at 14:42
Okay I'll try it now. I'm not good at kind of proofs. –  japee May 8 '12 at 14:45
I can only give result for $\lambda(f^+(x)>0)=\lambda(f^-(x)>0)$, not $\lambda(f(x)!=0)=0$ using that inequality in first problem. How can I go more steps? –  japee May 8 '12 at 15:20
I wrote an answer addressing the same problem in two dimensions. Warning: it's more than a hint. –  Ben Derrett May 8 '12 at 16:27

Assume $f \geq 0$. Then, for every $n \in \mathbb{N}$, consider $A_n = \{ x \in X \mid f(x)>1/n\}$. Then $$\frac{1}{n} \mu (A_n) \leq \int_{A_n} f \, d\mu \leq \int_X f \, d\mu =0.$$ Hence $\mu(A_n)=0$ for every $n$, and $f(x) \leq 1/n$ for almost every $x \in X$. We conclude that $f=0$ a.e.
In the general case, write $f=f^{+}-f^{-}$. By assumption, $\int_E f^{+}\, d\mu=0$ for $E=\{x \in X \mid f(x) \geq 0\}$. Therefore $f^{+}=0$ a.e. You can conclude in a similar way that $f^{-}=0$ a.e.