Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 管道输入到已经运行的cpp程序? 包括_C++_Pipe - Fatal编程技术网

C++ 管道输入到已经运行的cpp程序? 包括

C++ 管道输入到已经运行的cpp程序? 包括,c++,pipe,C++,Pipe,假设这是我正在运行的代码: int main(int argc, char **argv) { bool running = true; string lineInput; while (running) { while (cin >> lineInput) { cout << lineInput; } } return 0; int main(int argc,char**argv){ bool running=true;

假设这是我正在运行的代码:

int main(int argc, char **argv) {

bool running = true;
string lineInput;
while (running)
{
    while (cin >> lineInput)
    {
        cout << lineInput;
    }
}

return 0;
int main(int argc,char**argv){
bool running=true;
字符串行输入;
(跑步时)
{
而(cin>>行输入)
{

cout您可以使用
mkfifo
,只需像从普通文件一样从程序中读取即可

还有

  • 管道
    插座(双方向)

我想你可以用一个命名的管道来实现这一点

mkfifo mypipe
./myProgram < mypipe &
cat file1.txt file2.txt file3.txt > mypipe
mkfifomypipe
./myProgrammypipe

pipe
socketpair
在这里没有帮助。你实际上回答了你自己的问题;你需要一个管道,所以使用mkfifo并在后台运行它-将你的程序链接到它,然后将你的输入提供给使用mkfifo创建的管道,这已经由csreap3rThanks回答了!正是我需要的。没问题。很高兴我能ld help!这确实有效,但一旦我的程序到达管道数据的末尾,它就会停止读取。因此,这似乎是一次性的。有没有任何方法可以使这项工作不需要每次重新启动程序?如果我可以连续将7或8个不同的文件放入管道中,并让程序对其进行处理,那将非常好ramSee更新了答案,我相信一旦数据通过管道传输,就会发送EOF,您可以对多个文件使用cat命令。@CM0491:为避免EOF:
tail-f mypipe./myProgram&