<wu*******@hotmail.com> wrote in message
news:10***************@clint.its.waikato.ac.nz...
Hi all,
I was writting 2 programs in c++ using linux.Say,one is app1 and another
one is app2,the app1 will generate 100 random numbers and then print
them on the standard output,and then the app2 needs to copy the numbers
from the standard output to its int array by doing this way: $ app1|app2
(a pipe ?
This mechanism is often called a 'pipe', yes. But that's an
operating system feature, not a language one. (Many operating
systems, e.g. Unix and Windows, do have this 'pipe' facility.)
I am a newbi,and not sure how to call that ).the app1 is
finished and numbers seem ok,the problem is ,how does app2 copy from
screen? like usual ? int main(int argc,char * argv[]) ?
Every C++ program must have a 'main()' function, yes. It
may optionally specify command line arguments, yes. But this
has nothing to do with i/o.
what special
header file do i need ?
#include the headers which declare the functions you use
(e.g. if you use 'printf()', #include <stdio.h> ).
and what function to use ?
If your operating system supports this 'piping', all you need
to do is write your output to 'stdout' ('printf()' writes to
'stdout', other i/o functions let you specify which stream),
and take your input from 'stdin' ('scanf()' reads from 'stdin').
Exactly which i/o functions you use depends upon what you're doing.
Just make sure you write to 'stdout', and read from 'stdin'.
If this does not work, then pursue help in a group that discusses
your particular operating system.
-Mike