The Linux kernel does not support C++ very well at all, and you can't use the <iostream>
- I suspect any of the STL is also completely out of the question, but it's been quite some time since I looked at C++ in Linux kernel mode.
The standard implementation of cout
and cerr
are using OS features, which of course won't work inside the kernel. So you mustn't use those. It would of course be possible to implement something that works the same way (call it kostream
), and kostream& operator<<(kostream& os, sometype value)
, which produces some output into a buffer, then use printk
or some of the primitives that printk
uses to produce the actual output.
No matter whether it is C or C++, you will eventually end up using printk
(or it's constituent parts) to print things in the Linux kernel.
Note that using fstream
or stringstream
is also not going to work inside the kernel.