4. Any function $f(x)$ defined on $(-\infty,+\infty)$ can be expressed as the sum of an odd function $g(x)$ and an even function $h(x)$, given $f(x)=\lg \left(10^{x}+1\right), x \in(-\infty$, $+\infty)$, then ( ).
A. $g(x)=x, h(x)=\lg \left(10^{x}+10^{-x}+2\right)$
B. $g(x)=\frac{1}{2}\left[\lg \left(10^{x}+1\right)+x\right], h(x)=\frac{1}{2}\left[\lg \left(10^{x}+1\right)-x\right]$
C. $g(x)=\frac{x}{2}, h(x)=\lg \left(10^{x}+1\right)-\frac{x}{2}$
D. $g(x)=-\frac{x}{2}, h(x)=\lg \left(10^{x}+1\right)+\frac{x}{2}$
4. C.
$g(x)+h(x)=\lg \left(10^{x}+1\right)$, then $g(-x)+h(-x)=\lg \left(10^{-x}+1\right)$, which means $-g(x)+h(x)=$ $\lg \left(10^{-x}+1\right)$, solving these equations simultaneously can yield $g(x)$ and $h(x)$.