c++ - 在 Linux 系统调用中的 C 程序中出现错误 ‘\342’ stray ‘\210’ stray ‘\222’

标签 c++ c linux systems-programming

<分区>

我正在尝试做一个关于 Robert Love 的书 Linux 系统编程,第 2 版(第 60-61 页)中的轮询系统调用的示例。我在 Code::Blocks 中复制粘贴了示例代码在 Ubuntu 14.04 (Trusty Tahr) 并尝试编译它,但我的代码中出现与杂散的“/342”、“/210”和“/222”相关的错误。

以下是代码:它在检查 if(ret == -1) 的第 18 行抛出错误

#include <stdio.h>
#include <unistd.h>
#include <poll.h>

#define TIMEOUT 5

/* Poll timeout, in seconds */
int main (void)
{
  struct pollfd fds[2];
  int ret;

  /* Watch standard input for input */
  fds[0].fd = STDIN_FILENO;
  fds[0].events = POLLIN;

  /* Watch standard output for ability to write (almost always true) */
  fds[1].fd = STDOUT_FILENO;
  fds[1].events = POLLOUT;

  /* All set, block! */
  ret = poll(fds, 2 , TIMEOUT*1000);

  if (ret == −1) {
    perror("poll");
    return 1;
  }

  if (!ret) {
    printf ("%d seconds elapsed.\n", TIMEOUT);
    return 0;
  }

  if (fds[0].revents & POLLIN)
    printf ("stdin is readable\n");

  if (fds[1].revents & POLLOUT)
    printf ("stdout is writable\n");

  return 0;
 }

错误是:

/home/eelab/sysprog/pollex/main.c|18| error: stray ‘\342’ in program|
/home/eelab/sysprog/pollex/main.c|18| error: stray ‘\210’ in program|
/home/eelab/sysprog/pollex/main.c|18| error: stray ‘\222’ in program|

现在,我在 Stack Overflow 上回答了类似的问题,他们提到了 ASCII 字符(如引号“”)的转换可能存在的问题。但是,我又在IDE中重写了所有引号。但它仍然在检查 if(ret == -1 ) 的行上抛出相同的错误。

最佳答案

上有不可打印的
if (ret == −1) {

替换为-

关于c++ - 在 Linux 系统调用中的 C 程序中出现错误 ‘\342’ stray ‘\210’ stray ‘\222’,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38343182/

相关文章:

c++ - 在Linux中,当同一套接字上的accept()调用正在进行时,套接字描述符在某些条件下从另一个线程关闭?

c++ - 为什么我的程序输出一个巨大的小数?

c - int 变量的大小

c# - 以编程方式卸载掌上电脑程序

objective-c - 如何在 Interface Builder 中使用结构中的值

linux - 从 args 中选择随机条目的更好方法?

c++ - 是否在返回之前销毁参数?

C++ 遍历某个子类的列表

c++ - 如何导致故意除以零?

linux - 将 `jobs -p` 的输出捕获到变量中