"uli" <NOSPAM_uvb@nurfuerspam.de> wrote in message news:<c62sdn$p8q$1@newssrv.muc.infineon.com>...[color=blue]
> Hi all!
> I'm posting to both newsgroups, because it's actually a C++ problem but
> could be that some of you using Matlab-&-MEX-&-C++ was struggling with the
> same problem.
>
> I'm trying to rewrite some Matlab routines in C++ for reusing them
> identically in Matlab and some other simulation tools. For computational
> algebra I want to use the Matrix Template Library (MTL,
>
http://www.osl.iu.edu/research/mtl/) which is written in C++ and therefore
> makes use of std::cout.
> I have to use the mexfunction-interface of Matlab to run C++ code within a
> Matlab simulation. Since I'm writing my code with MSVC++ 6.0 and running
> Matlab on Windows, together with MATLAB and MEX, I can't use "cout" but
> "printf" ('cause of the MSWindows specific Matlab-Terminal).
>
>
> However to come to my Problem now:
> To solve this I want to redefine std::cout (within a header of my individual
> MEXinterface.cpp) so that it makes use of printf() instead . Could someone
> give me some hints or links to information how I could manage this?[/color]
Sure, it's not very complex. Inside std::cout, there is something called
a streambuf. The default streambuf is responsible for writing the
already formatted text to the console (formatting was done by the
std::cout object itself). If you want to send the text to a different
destination, you will have to replace the streambuf. E.g. if you
want to redirect std::cout to a file, open a std::ofstream, and swap
the streambufs. If you have another destination, derive your
custom sterambuf from std::streambuf and implement the applicable
virtual functions.
Pointer: std::stream::rdbuf(std::streambuf*).
Regards,
Michiel Salters