我很期待学习如何在 Unix 中打印当前登录的用户和系统名称。
#include <unistd.h>
#include <fcntl.h>
using namespace std;
int main(int argc, char **argv)
{
//Print the current logged-in user / username.
//Print the name of the system / computer name.
return 0;
}
如果您能提供一两行代码作为演示,我将不胜感激。谢谢
用户-->getuid()
(也可以看看geteuid()
).
机器名称-->gethostname()
.
那是纯 C 语言。我不知道 C++ 是否有其他库调用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)