错误:在'='标记之前预期的primary-expression和许多其他标记

Jak*_*sky -1 c++

我是盲人还是没有错误.我认为这可能是第一选择.请帮我在大海捞针找到针.这是我的错误列表的一部分:

server.cpp: In function ‘int main(int, char**)’:
server.cpp:64:16: error: expected primary-expression before ‘=’ token
server.cpp:71:14: error: expected primary-expression before ‘=’ token
server.cpp:71:24: error: expected primary-expression before ‘)’ token
server.cpp:71:24: error: expected ‘;’ before ‘)’ token
server.cpp:72:12: error: expected primary-expression before ‘=’ token
server.cpp:80:10: error: expected primary-expression before ‘=’ token
make: *** [server] Error 1
Run Code Online (Sandbox Code Playgroud)

这是我的代码的一部分:

#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <netdb.h>
#include <iostream>
#include <regex.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <locale.h>
#include <cstring>
#include <signal.h>
#include <dirent.h>

using namespace std;

/* global variables */
// error codes
#define ERR_OK = 0;
#define ERR_PARAMS = 1;
#define ERR_SOCKET = 2;
#define ERR_BIND = 3;
#define ERR_OTHER = 99;

// others
#define LISTEN_BACKLOG 50

/* function prototypes */
void printErr(int EC);
int second(int port);

int main(int argc, char **argv)
{
  int pflag = 0;
  string pvalue;
  int port;
  int c;

  opterr = 0;
  while((c = getopt (argc, argv, "p:")) != -1) {
    switch(c) {
      case 'p':
        pflag = 1;
        pvalue.assign(optarg);
      break;
      case '?':
        if(optopt == 'c')
          fprintf(stderr, "Option -%c requires an argument.\n", optopt);
        else if(isprint (optopt))
          fprintf(stderr, "Unknown option `-%c'.\n", optopt);
        else
          fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
        return ERR_PARAMS;
      default:
        abort();
    }
  }

  if(pflag == 0) {
    printErr(ERR_PARAMS);
    return ERR_PARAMS;
  }
  printf ("pvalue = %s\n", pvalue.c_str());

  port = atoi(pvalue.c_str());

  second(port);

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

我在整个代码中有更多类似的错误,所以我认为有些东西就像缺少了一些东西.你看到了吗?我不.

Ben*_*igt 5

其他答案是正确的,问题是符号常量

#define ERR_OK = 0;
#define ERR_PARAMS = 1;
#define ERR_SOCKET = 2;
#define ERR_BIND = 3;
#define ERR_OTHER = 99;
Run Code Online (Sandbox Code Playgroud)

但是,在C++中有一种更好的方法来解决这些问题:

const int ERR_OK = 0;
const int ERR_PARAMS = 1;
const int ERR_SOCKET = 2;
const int ERR_BIND = 3;
const int ERR_OTHER = 99;
Run Code Online (Sandbox Code Playgroud)

或者,C和C++都允许

enum ERROR_CODES {
  ERR_OK,
  ERR_PARAMS,
  ERR_SOCKET,
  ERR_BIND,
  ERR_OTHER = 99
};
Run Code Online (Sandbox Code Playgroud)