windows下c++如何读取主机名

#include 
#include 
#include 
#include 
#include 
using namespace std;

int main() {
    TCHAR buf[MAX_COMPUTERNAME_LENGTH + 2];
    DWORD buf_size;
    buf_size = sizeof buf - 1;
    GetComputerName(buf, &buf_size);
    string a = buf;
    cout << a << endl;
    return 0;
}

你可能感兴趣的:(c++,windows)