在我的另一个问题中,一个用户通过共享内存帮助我发送字符串。但是,当我尝试接收此数据时,getWindow()
说。我试试这段代码:
Core dumped
我还尝试将其重写为key_t lineKey = ftok("/tmp", '1');
int sharedLine = shmget(lineKey, sizeof(std::string), IPC_CREAT | 0666);
std::string *line = (std::string *)shmat(sharedLine, NULL, 0);
sem_t *reader1_sem;
reader1_sem = sem_open("reader1_sem", O_CREAT, 0666, 0);
while (1) {
sem_wait(reader1_sem);
std::cout << (*line);
}
,但它也不起作用(char *
)。