Com*_*org 4 c++ unix shell username
我期待着学习如何在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;
}
Run Code Online (Sandbox Code Playgroud)
如果您能提供一行或两行代码作为演示,我将不胜感激.谢谢
用户 - > getuid()
(另见geteuid()
).
机器名称 - > gethostname()
.
这是纯粹的C.我不知道C++是否有其他库调用.