-2
我正在做一些工作在unix與c + +我試圖創建一個命名管道之間我的兩個程序,併發送一些文本來回之間。我讓我的系統調用運行server.cpp我收到此錯誤信息。語法錯誤附近意想不到的令牌'''''
./server.cpp: line 8: syntax error near unexpected token '('
./server.cpp: line 8: 'void test()'
是什麼原因造成這個錯誤?我沒有與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;
}
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);
}
你不應該運行的二進制文件,而不是.cpp文件? – Xarn
server.cpp還需要一個'main()'函數(除其他外) – ryyker