#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 function returns NULL and error "No such file or directory"的评论我试过在网上搜索但是找不到任何相关的答案。
SYNOPSIS
#include <unistd.h> #include <sys/types.h> uid_t getuid(void); uid_t geteuid(void);
你错过了那些包括。
getuid()
不在pwd.h
。见http://pubs.opengroup.org/onlinepubs/7908799/xsh/pwd.h.html