如何:检索当前用户名 (C++/CLI)

下面的代码示例演示如何检索当前用户名(已登录到 Windows 的用户的名称)。 该名称存储在 UserName 字符串(在 Environment 命名空间中定义)中。

示例

// username.cpp
// compile with: /clr
using namespace System;

int main() 
{
   Console::WriteLine("\nCurrent user: {0}", Environment::UserName);
   return 0;
}

请参见

其他资源

Windows 操作 (C++/CLI)

编程在Visual C++的.NET