Exercise: Let $f,g:S\to\overline{\mathbb{R}}$ both be measurable functions. Assume that $f$ is integrable and that $f=g$ almost everywhere (a.e.). Show that $g$ is integrable and $$\int_E f\,d\mu = \int_E g\,d\mu, \,\, E\in\mathcal{A},$$ where $\mathcal{A}$ is the $\sigma$-algebra of $S$.
What I've tried:
Since $f = g$ a.e., we know that $\left|g-f\right| = 0$, a.e. If $f$ is a measurable function then $\int_S f\,d\mu = 0$ if and only if $f = 0$ a.e. Therefore, I know that $\int_S \left|g-f\right|\,d\mu = 0.$
Furthermore, a measurable function $f$ is integrable if $\int_E f^+ \,d\mu$ and $\int_E f^-\,d\mu$ are finite. Since $\left|f\right| = f^+ + f^-$, we know that $g-f$ is integrable, because $\int_E\left|g-f\right|\,d\mu = \int_E(g-f)^+\,d\mu + \int_E(g-f)^-\,d\mu = 0$. Since $f$ is integrable we know that $g = (g-f) + f$ is integrable. Lastly $\left|\int_E g\,d\mu - \int_E f\,d\mu\right| = \int_E\left|g-f\right|\,d\mu \leq \int_S\left|g-f\right|\,d\mu = 0,$ concluding the proof.
Apparently this is the solution for the case when $f,g$ take values only in $\mathbb{R}$. The next step would be to evaluate the positive and negative parts when $f,g \in \overline{\mathbb{R}}$.
The second part of the solution starts like this:
Let $A = \{x\in S: f(x) = g(x) \text{ and } \left|f(x)\right| <\infty\}.$ Then by subadditivity $\mu(A^c) = \mu(\{f\neq g\}\cup \{\left|f\right|<\infty\})\leq \mu(\{f\neq g\} + \mu(\{\left|f\right|=\infty\}) = 0.$ Now let $h:S\to[0,\infty]$ be a measurable function such that $h(x)<\infty$ for all $x\in A$. Then $h-\mathcal{1}_A h\cdot\mathcal{1}_{A^c}h = 0$$h-\mathcal{1}_A h\cdot\mathcal{1}_{A^c}h$ a.e. and therefore $$\int_S \mathcal{1}_{A^c}h\,d\mu = 0.$$ Adding $\int_S\mathcal{1}_Ah\, d\mu$ on both sides and using linearity we find $$\int_S h\,d\mu = \int_A h\,d\mu.$$
From here on, after we've obtained that $\int_S h\,d\mu = \int_A h\,d\mu,$ I understand the solution, but I do have a couple of questions about the first part that's given above.
Questions:
First and foremost; why does the the second part of the solution addresses the fact that $f,g$ can take values in $\overline{\mathbb{R}}$, while my solution doesn't?
How do you know that $h-\mathcal{1}_A h\cdot\mathcal{1}_{A^c}h = 0$ is a.e.?
Why does $h-\mathcal{1}_A h\cdot\mathcal{1}_{A^c}h = 0$ a.e. somehow imply that $\int_S \mathcal{1}_{A^c}hd\mu = 0.$ The only way this works is if $h-\mathcal{1}_A h\cdot\mathcal{1}_{A^c}h = \mathcal{1}_{A^c} h$.
Thanks in advance!