为什么我得到" getuid没有在该范围内宣布"错误?

时间:2018-06-16 13:03:06

标签: c++ getpwuid

#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&#39的回答getlogin() c function returns NULL and error "No such file or directory"的评论 我尝试在网上搜索,但无法找到相关的答案。

2 个答案:

答案 0 :(得分:6)

man getuid

  

概要

arr.push(alphabet.indexOf((str[i] +1)*2))

你错过了那些包含。

答案 1 :(得分:1)

相关问题