[英]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;
}
我需要知道用戶的用戶名 。 為此。 我正在使用getpwuid()
但出現此錯誤。
/home/shobhit/Desktop/file.cpp:15: error: 'getuid' was not declared in this scope
pass = getpwuid(getuid());
^
我只是不知道在此范圍內未聲明getuid的原因是什么。 我想我已經包括了所有必需的頭文件。(yami對R的答案getlogin()c函數的評論返回NULL,並且錯誤“我沒有嘗試過在網絡上搜索此文件或目錄” ,但找不到任何相關的答案。
概要
#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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.