为什么我会收到"getuid was not declared in that scope"错误?
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和错误"没有这样的文件或目录" 我尝试在网上搜索,但找不到任何相关的答案。
man getuid
:
概要
#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
相关文章:
- 如何修复"error: ‘_1’ was not declared in this scope"?
- 类中的数组变量C++导致"was not declared in this scope"实现文件的一个函数中错误,但在构造函数中不会导致错误
- 如何解决"cout was not declared in this scope"错误?
- 为什么程序显示我"was not declared in this scope"?
- 为什么我会收到"getuid was not declared in that scope"错误?
- 即使包含 <time.h 后仍"‘CLOCK_PER_SEC’ was not declared in this scope"错误>
- 将数据添加到 CArray 会产生错误"cannot access private member declared in class 'CObject'"
- 我正在接受"Error: string was not declared in this scope"
- C++ 我一直在"was not declared in this scope error"
- 将 .ui 文件导入 Qt5 C++时出错"was not declared in this scope"
- 编译 CPP 应用程序时出错。 "error: 'posix_memalign' was not declared in this scope"
- main.cpp中的错误:函数库中的函数"not declared in this scope",但实际上是
- "Error: 'dungeon_t' was not declared in this scope"但包含在标题中
- C++ 中的" Variable ' i ' was not declared in scope "是什么?
- "pointer was not declared in this scope"是什么意思
- 学习如何在遇到错误'variable not declared in scope'的 c++ 中使用指针
- "error: not declared in this scope?"是什么意思
- 宣布时的另一个'not declared in this scope'问题
- " 'X' not declared in this scope "错误
- 子类模板错误 (C++): "error: 'root' was not declared in this scope"