阅读前请看一下:我是一个热衷于记录的人,每次写博客会反复研读,尽量不断提升博客质量。文章设置为仅粉丝可见,是因为写博客确实花了不少精力。希望互相进步谢谢!!
文章目录
提示:以下是本篇文章正文内容
1、问题描述
背景:
Windows网络编程,devC++运行cpp程序,报如下错:
error: ‘getpid’ was not declared in this scope
错误代码行:
int ident = getpid();//取得进程识别码
2、问题分析
getpid() 函数是linux下网络编程的函数,不能加linux下的头文件,识别不出来。
3、解决办法
方法一,下面两个头文件增加任何一个即可,即以下两个头文件适用于windows下获取进程号的getpid()函数
#include <process.h>
#include <unistd.h>
方法二,getpid()
函数换成 GetCurrentProcessId()
函数
int ident = GetCurrentProcessId();//取得进程识别码
码字不易,谢谢点赞!!!
码字不易,谢谢点赞!!!
码字不易,谢谢点赞!!!