#include <winsock2.h>
#include <ws2tcpip.h>
#include <iostream>
#pragma comment(lib, "ws2_32.lib")
using namespace std;
#define listen_port 12345;
int main() {
...
cout << "Server is listening on port " << listen_port << endl;
...
}
- 运行上述 C++ 代码,报如下错误
E0029 应输入表达式
C2059 语法错误:“<<”
问题原因
- 这个问题是语法错误导致的,
#define
语句末尾不应该有分号
处理策略
- 删除
#define
语句末尾的分号
#define listen_port 12345
- 或者,使用 C++ 的常量定义方式
const int listen_port = 12345;