简体   繁体   English

为什么我收到“未在该范围内声明getuid”错误?

[英]Why I am getting “getuid was not declared in that scope” error?

#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;
}

I need to know username of the user. 我需要知道用户的用户 In order to do this. 为此。 I am using getpwuid() but I am getting this error. 我正在使用getpwuid()但出现此错误。

/home/shobhit/Desktop/file.cpp:15: error: 'getuid' was not declared in this scope
 pass = getpwuid(getuid());
                        ^

I just couldn't figure out what is the reason that getuid is not declared in this scope. 我只是不知道在此范围内未声明getuid的原因是什么。 I think I have included all the necessary header files.(yami's comment on R's answer getlogin() c function returns NULL and error "No such file or directory" I have tried searching on the web but couldn't find any relevant answer. 我想我已经包括了所有必需的头文件。(yami对R的答案getlogin()c函数的评论返回NULL,并且错误“我没有尝试过在网络上搜索此文件或目录” ,但找不到任何相关的答案。

man getuid : man getuid

SYNOPSIS 概要

 #include <unistd.h> #include <sys/types.h> uid_t getuid(void); uid_t geteuid(void); 

You're missing those includes. 您缺少这些包括。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我会收到“未在此范围内声明”错误? - why am I getting a “was not declared in this scope” error? 为什么我在这个 scope 中没有声明错误? - Why i am getting error not declared in this scope? 为什么我没有在此 scope 错误中声明 - Why am I getting not declared in this scope error 为什么我在声明本身中收到“未在范围内声明”错误? - Why am I getting a "not declared in scope" error in the declaration itself? 当我包含windows.h时,为什么会出现错误“在此范围内未声明WM_MENUCOMMAND”? - Why am I getting the error “WM_MENUCOMMAND was not declared in this scope” when I included windows.h? 为什么我会收到编译错误“ <variable> 没有在此范围内声明”? - Why am I getting compile errors “<variable> not declared in this scope”? 无法实例化好友函数中的类? 我没有在范围错误中声明 - Not able to Instantiate class inside friend function? I am getting not declared in scope error 我在 c++ 中遇到错误“PTHREAD_START_ROUTINE”未在此范围内声明 - I am getting error in c++ 'PTHREAD_START_ROUTINE' was not declared in this scope 我收到“错误:字符串未在此范围内声明” - I'm getting an "Error: string was not declared in this scope" 获取“未在此范围内声明”错误 - Getting a 'was not declared in this scope' error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM