我期待着学习如何在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;
}如果您能提供一两行代码作为演示,我将不胜感激。谢谢
发布于 2012-01-04 16:32:03
您需要调用uname、gethostname、getuid (可能还有getgid) system calls,并使用getpwent函数转换数字uid。
https://stackoverflow.com/questions/8723956
复制相似问题