I learnt that the integral of a function $f(\cdot)$ is the measure of an area, i.e. $\int\limits_{a}^{b}f(x)\,\mathrm{d}x$ is the area of the intersection of $x=a$, $x=b$, and $y=f(x)$.
How come some areas are non-positive.
Example: $\int\limits_{0}^{\pi}\cos x\,\mathrm{d}x=0\leq 0$.
It's simply not true, in general, that $\int_a^b f(x) \,dx$ is equal to the area between $f(x)$ and the $x$-Axis in the interval $[a,b]$. For precisely the reason you stated - areas obviously cannot be negative.
What is true is that for non-negative functions $f(x)$, the area between $f(x)$ and the $x$-Axis in the interval $[a,b]$ is $\int_a^b f(x) \,dx$. Though note that this is more a definition of that area then anything else - how would you compute that area without resorting to integration? The only thing you can really prove is that this notion of area coincides with other definitions of area for simple shapes like rectangles.
For general functions $fx$, $\int_a^b f(x) \,dx$ is the difference between the area above the $x$-Axis and below $f(x)$, and the area below the $x$-Axis and above $f(x)$. We chose to define the integral that way because it then has a lot of convenient properties. For example, we then get $$ \int_a^b - f(x) = -\int_a^b f(x) \text{.} $$
For similar reasons, we also define $$ \int_a^b f = - \int_b^a f \text{.} $$