We can talk about C more easily, because it's a very basic language and really a little more higher over asm.
The answer is: system calls.
You could wonder: why? There are things that a language cannot do. And I/O is one of those. I/O streams are "owned" by the Operating System. It handles them.
The OS allows you to use them, but you must always rely on it before.
System calls are very basic: there are no format strings or whatever, for example.
Also you need to consider that system calls are OS-dependent. Windows' ones are different from Linux's ones.