473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

how to copy from std optput ?

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 ? 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[]) ? what special
header file do i need ? and what function to use ?
Thanks a lot guys!!
Jul 22 '05 #1
2 1399
<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
Jul 22 '05 #2
"Mike Wahler" <mk******@mkwahler.net> wrote in message news:<JK******************@newsread1.news.pas.eart hlink.net>...
<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 ?


You don't have to worry about the redirection. app1 will normally
write to its standard output (which could be a terminal) and app2 may
read its input from its standard input (which could be the keyboard).
What you have to worry about is the creation of a pipe whose one end
will be connected to the standard output of app1 and the other end
should be connected to the standard input of app2.

To implement this pipe, you need not do anything at the language level
but the OS provides you with the basic facility. You can simply do $
app1 | app2
This will connect the output of app1 to the input of app2.
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
15
by: A | last post by:
Hi, A default copy constructor is created for you when you don't specify one yourself. In such case, the default copy constructor will simply do a bitwise copy for primitives (including...
2
by: Alex | last post by:
Entering the following in the Python shell yields >>> help(dict.copy) Help on method_descriptor: copy(...) D.copy() -> a shallow copy of D >>>
24
by: rdc02271 | last post by:
Hello! Is this too crazy or not? Copy constructor: why can't I copy objects as if they were structs? I have a set of simple objects (no string properties, just integers, doubles) and I have to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.