// C includes #include #include #include #include #include // C++ includes #include #include using namespace std; int main(){ char buffer[HOST_NAME_MAX]; int retval = gethostname(buffer, sizeof(buffer)); string hn = buffer; printf("The host's name is %s\n", hn.c_str()); printf("Return status %d\n", retval); if(retval){ printf("errno = %d\n", errno); perror("gethostname"); } strcpy((char*)hn.c_str(), "salmon"); printf("hn = %s\n", hn.c_str()); cout << "cout: hn = " << hn << endl; printf("Length of hn: %d\n", hn.length()); return 0; }