我有这段代码试图将我从管道(fd_3)收到的行写入输出文件。writer 打印接收到的行;然后这些行被正确打印,但输出文件每次都是空白的。有任何想法吗?
close(fd_3[WRITE_END]); //wont be writing to Munch2
ofstream outFile;
outFile.open("output.txt");
if(!outFile) {
printf("File output.txt could not be opened");
}
while(read(fd_3[READ_END], (void*)line.c_str(), BUFFER_SIZE)) {
printf("writer receives: %s\n", line.c_str());
outFile << line;
}
outFile.close();
close(fd_3[READ_END]); //done reading