解决方法
视窗
例:
char user_name[UNLEN+1]; DWORD user_name_size = sizeof(user_name); if (GetUserName(user_name,&user_name_size)) cout << "Your user name is: " << user_name << endl; else /* Handle error */
Linux的
看看getpwuid:
The getpwuid() function shall search
the user database for an entry with a
matching uid.The getpwuid() function shall return a
pointer to a struct passwd
struct passwd将包含char * pw_name.