This is called the fundamental theorem of affine geometry. Let $f : E \to E'$ be a map between affine spaces over a field $K$. Suppose that

$f$ is bijective;

$\dim E=\dim E'\ge 2$;

If $a, b, c\in E$ are aligned, then so are $f(a), f(b), f(c)$.

Then $f$ is semi-affine: fix some $a_0\in E$, then there exists a field automorphism $\sigma$ of $K$ such that the map $h: v\mapsto f(a_0+v)-f(a_0)$ (which goes from the vector space attached to ${E}$ to that attached to $E'$) is additive and $h(\lambda v)=\sigma(\lambda)h(v)$ for all $v$ and all $\lambda \in K$. I don't have an URL for this theorem, I find it in Jean Fresnel: * Méthodes Modernes en Géométrie*, Exercise 3.5.7. But I think it is in any standard textbook on affine geometry.

When $K=\mathbb R$, it is known that $K$ has no non-trivial field automorphism. So your $f$ is an affine function, hence continuous. If $K=\mathbb C$, as pointed out by Kevin in above comments, take any non-trivial automorphism of $\mathbb C$, then you get a semi-affine map $\mathbb C^n \to \mathbb C^n$ which will not be affine, even not continuous (if $\sigma$ is not the conjugation).