Hi,
The short story: I have to redirect stdout (not cout!!) to an ostream.
How can I manage this?
The long story:
I use the NAGC numerics library with C++ and want to use its output
routines for e.g. complex matrices. The problem: You can either print
to a file (given by filename) or to stdout. To call the NAGC-method
within an operator<< thus I have to redirect stdout to the given
ostream. But how can I initialize an ostream from a FILE *?
regards,
alex 4 6293
"Alexander Stippler" <st**@mathematik.uni-ulm.de> wrote... The short story: I have to redirect stdout (not cout!!) to an ostream. How can I manage this?
The long story: I use the NAGC numerics library with C++ and want to use its output routines for e.g. complex matrices. The problem: You can either print to a file (given by filename) or to stdout. To call the NAGC-method within an operator<< thus I have to redirect stdout to the given ostream. But how can I initialize an ostream from a FILE *?
It's not a good idea to use a numerics library that has some output
(beyond reporting terminal conditions). Contact the makers of the
library and ask them to give you an option to define where the output
goes. Better yet, make them remove all output from the _numerics_
library and leave only the calculations in.
Just MHO.
You misunderstood my intention. NAGC has very nice and
customizable routines for printing matrices. Think of large
matrices with hundreds of columns. You have to split rows into sectors,
you have to determine the width of each element and so on to get a version
readable on a normal terminal.
So I do not want to this work on my own. But the library, which is
written in plain C offers two targets for printing only. A file (given by
filename) or stdout.
And now I want to redirect this given stdout to an ostream. because I
want to provide something like
std::ostream &
operator<<(std::ostream &out, const ComplexMatrix &C)
{
--> redirect stdout to out.
// here NAGC does all the work.
return out;
}
I hope now it's clear. Short again: I have to redirect the 'C-style' stdout
to a 'C++-style' std::ostream. Is there a possibility?
alex
P.S.: I consider it absolutely hopeless to have NAGC modify its interface.
"Alexander Stippler" <st**@mathematik.uni-ulm.de> wrote... You misunderstood my intention. NAGC has very nice and customizable routines for printing matrices. Think of large matrices with hundreds of columns. You have to split rows into sectors, you have to determine the width of each element and so on to get a version readable on a normal terminal. So I do not want to this work on my own. But the library, which is written in plain C offers two targets for printing only. A file (given by filename) or stdout. And now I want to redirect this given stdout to an ostream. because I want to provide something like
std::ostream & operator<<(std::ostream &out, const ComplexMatrix &C) { --> redirect stdout to out. // here NAGC does all the work. return out; }
I hope now it's clear. Short again: I have to redirect the 'C-style'
stdout to a 'C++-style' std::ostream. Is there a possibility?
Of course there is a possibility. Reopen stdout as a temporary file, let
them write the matrix there, read it and then output it where you need it.
That's the simplest way I know.
You don't have to reopen stdout, though, since they provide output to
a file. Just slip them your temporary file and once they've done with
it, read it and output where needed.
You could try working around FILE*/stream incompatibility by providing
your own stream buffers, and I am sure somebody has done that before.
Try googling for something like "open fstream fopen". alex
P.S.: I consider it absolutely hopeless to have NAGC modify its interface.
What do they consider? Have you asked?
Victor Bazarov wrote: Of course there is a possibility. Reopen stdout as a temporary file, let them write the matrix there, read it and then output it where you need it. That's the simplest way I know.
You don't have to reopen stdout, though, since they provide output to a file. Just slip them your temporary file and once they've done with it, read it and output where needed.
That is of course possible. But is it reasonable to open a file if you just
want to print to screen? You have to have write permissions to do so (OK,
you
could take /tmp), but our program has to be portable even for windows.
It would be enough to redirect stdout/stderr to their counterpart.
You could try working around FILE*/stream incompatibility by providing your own stream buffers, and I am sure somebody has done that before. Try googling for something like "open fstream fopen".
That's much overhead. Too much for me (and a little of topic for our
library).
regards,
alex This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Birch |
last post by:
I have a python script that uses the print function throughout, and as
well uses calls to os.system() to spawn DOS commandline executables.
My issue is that I redirect all of the output from this...
|
by: David Douard |
last post by:
Hi everybody,
let me explain by problem:
I am working on an application which consists in a C++ dll (numeric
computations) and a Python IHM (Python/Tk), which must run under Linux and
win32. My...
|
by: Laszlo Zsolt Nagy |
last post by:
Hello,
I have this code:
s = smtplib.SMTP()
s.set_debuglevel(1)
s.connect(host=smtp_host)
s.set_debuglevel(0)
log("Connected, sending e-mail")
sys.stdout.flush()
|
by: Matt Burland |
last post by:
I'm having a problem with redirecting the StandardOutput of a process that I
use to run a DOS program in my application. The problem is that I when I
start my process (which I do in a separate...
|
by: Fuzzyman |
last post by:
Hello,
I'm trying to redirect standard out in a single namespace.
I can replace sys.stdout with a custom object - but that affects all
namespaces.
There will be code running simultaneously...
| |
by: Morpheus |
last post by:
I am trying to test a function that outputs text to the standard
output, presumably using a cout call. I do not have access to the
source, but need to test the output. Is this possible?
I can...
|
by: pp4175 |
last post by:
Hello Everyone,
I am currently working on writing a GUI wrapper for a Menu driven DOS
Program. What I was looking on doing is redirecting stdout/stdin to a stream
and read/write similar to a...
|
by: twiggy182 |
last post by:
Hi,
I really need you help because I'm not very familliar with ASP and I
could not find any solution to my problem.
To put you in situation, I have a CGI to which I send a file name, and
that...
|
by: drhilbert |
last post by:
Dear all,
in these days, we have found a problem we can't solve even after long
long googling, so we are here asking your precious help.
In our program instead of using cout to print messages...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |