#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());
^
我就是不明白为什么
获取用户ID
未在此范围内声明。我想我已经包含了所有必要的头文件。(Yami对R的回答有评论)
getlogin() c function returns NULL and error "No such file or directory"
我试过在网上搜索,但找不到任何相关的答案。