小编And*_*OSU的帖子

意外令牌附近的语法错误'('

我正在使用c ++在unix中做一些工作.我试图在我的两个程序之间创建一个命名管道,并在它们之间来回发送一些文本.一切编译都很好,但当我调用我的系统运行server.cpp时,我收到此错误消息.

./server.cpp: line 8: syntax error near unexpected token '('
./server.cpp: line 8: 'void test()'
Run Code Online (Sandbox Code Playgroud)

导致此错误的原因是什么?我对unix或命名管道没有多少经验,所以我有点难过.

这是我的代码

client.cpp

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>

int main()
{
   int fd;

   mkfifo("home/damil/myPipe", 0666);

   fd=open("home/damil/myPipe", O_WRONLY);
   write(fd,"test", sizeof("test")+1);

   system("./server.cpp");
   close(fd);

   return 1; 
}
Run Code Online (Sandbox Code Playgroud)

server.cpp

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>

void test()
{
   int fd;
   char * comm;

   fd = open("home/damil/myPipe", O_RDONLY);   
   read(fd, comm, 1024);
   printf(comm);
   close(fd);
}
Run Code Online (Sandbox Code Playgroud)

c c++ unix named-pipes

-2
推荐指数
1
解决办法
2366
查看次数

标签 统计

c ×1

c++ ×1

named-pipes ×1

unix ×1