I have a two C++ source code in which one code generates an array for the specified input while other has to use array for execution. I want to know how can I link two C++ file such that output of the first file is the input for second one ?
-
What do you mean with C++ file? Two seperate programs or just two seperate cpp files in a project? Is it a small array of numbers or a big binary data array? – typ1232 Jun 08 '13 at 19:48
-
It is two separate programs, and the output is big binary data array. – user2406568 Jun 08 '13 at 19:55
2 Answers
Since they're separate programs, that means they each have a main() function. Because of that you can't link them together. What you can do, however, is use the shell to redirect the output from one program to the input of another. For example:
program1 | program2
The above creates a so-called "pipe". What it does is feed program2 with the output of program1. Only the standard input and standard output are redirected that way. In C++ that means std::cin and std::cout. Anything printed on std::cerr or std::clog is not redirected, so make sure to never print errors, warnings or other status/informational messages on std::cout. Only print the payload data and use std::cerr or std::clog for anything else.

- 50,738
- 9
- 71
- 96
-
The array generated in not just simple array but a big binary array containing numbers and string too. – user2406568 Jun 08 '13 at 19:57
-
@user2406568 Try to read the data anyway. See these answers on how you can do it: http://stackoverflow.com/q/7587595/856199 – Nikos C. Jun 08 '13 at 20:04
Linux: Compile both files and push the content of the first to the second binary with a pipe in terminal else use a socket.. you can try to ouput the data with a binary-stream and the second binary can use the same techniqe to pushs it into a array.. i hope that helps you..

- 1
- 2