获取计算机名
1 #include <string> 2 #include <iostream> 3 #include <stdlib.h> 4 #include <time.h> 5 #include <algorithm> 6 7 using namespace std; 8 int main() 9 { 10 char* szComputerNameTemp; 11 size_t sz = 0; 12 errno_t err = _dupenv_s(&szComputerNameTemp, &sz, "COMPUTERNAME"); 13 14 string strComputerName = ""; 15 strComputerName = szComputerNameTemp; 16 transform(strComputerName.begin(), strComputerName.end(), strComputerName.begin(), ::toupper);//转化为大写 17 18 cout << strComputerName << endl; 19 20 cin.get(); 21 return 0; 22 }