Boost logo

Boost Users :

Subject: Re: [Boost-users] (Boost.Python) How to print from C++ to the same stream as Python's 'print' does?
From: Early Ehlinger (earlye_at_[hidden])
Date: 2009-05-11 17:17:50


This is very old and probably largely wrong by now, but the general concept
is the same.

http://www.respower.com/~earlye/programming/19991206.001.htm

Basically, you need to create a streambuf class that calls
PySys_WriteStdout() inside your_streambuf_class::sync().

-- Early Ehlinger

On Mon, May 11, 2009 at 11:11 AM, Dietrich Bollmann <diresu_at_[hidden]> wrote:

> Hi,
>
> I would like to print from C++ to the same stream as Python's 'print'
> command does. I am using an embedded Python shell and when using
> std::cout nothing is printed at all...
>
> Currently I am using the following code:
>
> std::ostringstream oss;
> oss << "test\n";
> std::string cs = oss.str();
> PySys_WriteStdout(cs.c_str());
>
> I wonder if there is an easier way to get the same result?
>
> Thanks, Dietrich
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
Early Ehlinger


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net