This question already has an answer here:
Let $S\subset \Bbb R$ non-empty, open and closed. Fix $x_0\in S$. Let $I:=\{r>0,[x_0-r,x_0+r]\subset S$. As $S$ is open, $I$ is non-empty. If $I$ is bounded, let $\{r_n\}$ a sequence which increases to $\sup I$. Then $x_0+r_n\in S$ for each $n$, and as $S$ is closed $x_0+\sup I\in S$. But $S$ is open, so we can find $\delta>0$ such that $x_0\pm \sup I\pm t \in S$ for $0\leq t\leq \delta$, hence $\sup I+\delta\in I$, a contradiction.
So $S=\Bbb R$.
Note that such an approach works for $\Bbb R^d$ instead of $\Bbb R$. Just replace the interval $[x_0-r,x_0+r]$ by the closed ball $\bar B(x^{(0)},r):=\{x\in\Bbb R^d,\max_{1\leq j\leq d}|x_j-x_j^{(0)}|\leq r\}$.
Assume $U$ and its complement $V$ are both non-empty open subsets of $\mathbb R$. Then there are $x \in U$ and $y \in V$ and by switching the roles of $U$ and $V$, if necessary, we may assume $x < y$. Now let
$$a = \sup\{b \in \mathbb R : [x,b] \subseteq U \}$$
(the supremum exists since $x \in U$ and $y \not\in U$ and $x<y$). If $a \in U$ then, since $U$ is open, $a + \varepsilon \in U$ for small $\varepsilon$, contradicting the definition of $a$. Otherwise, if $a \in V$ then, since $V$ is also open, $a-\varepsilon \in V$ for small $\varepsilon$, again contradicting the definition of $a$.
Take a set $A\subseteq \bf R$ which is closed and open. Suppose towards contradiction that $A$ is not the entire $\bf R$ and nonempty. Then there is some point $x_1\notin A$ and $x_0\in A$. Without loss of generality $x_0<x_1$.
Consider the interval $I=[x_0,x_1]$. $I\cap A$ is an intersection of closed sets, so it is closed, so $x’=\sup(I\cap A)$ is in $I\cap A$. Obviously, $x'<x_1$. But $A$ is open, so there is an $\varepsilon>0$ such that $(x’-\varepsilon,x’+\varepsilon )\subseteq A$, but then there’s some other point of $A$ in $(x’,x_1]$, so we have a contradiction.