#include <string>
#include <stdio.h>
#include <pwd.h>
std::string impPath()
{
char *name;
struct passwd *pass;
pass = getpwuid(getuid());
name = pass->pw_name;
std::string PATH = "/home";
PATH.append("/");
PATH.append(name);
return PATH;
}
我需要知道用户的用户名。为此。我正在使用getpwuid()
,但出现此错误。
/home/shobhit/Desktop/file.cpp:15: error: 'getuid' was not declared in this scope
pass = getpwuid(getuid());
^
我只是无法弄清楚getuid未在此范围内声明的原因是什么。我想我已经包含了所有必要的头文件。(yami 对 R 的答案getlogin() c 函数的评论返回 NULL 和错误“没有这样的文件或目录” 我尝试在网上搜索但找不到任何相关的答案。