且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获取当前用户的用户名?

更新时间:2023-11-30 10:39:58

#include  <stdio.h>

int main(void)
{
    printf("%s\n", getenv("USERPROFILE"));  // Print user's home directory.
    return 0;
}

要获取用户名而不是主路径,请将 USERPROFILE 替换为 USERNAME.

To get the user name instead of the home path replace USERPROFILE with USERNAME.