Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. string Linux::getHostName()
  2. {
  3.     string host = "";
  4.     ifstream myReadFile;
  5.     myReadFile.open("/etc/hostname");
  6.     if (myReadFile.is_open())
  7.     {
  8.         while (!myReadFile.eof())
  9.         {
  10.             myReadFile >> host;
  11.             return host;
  12.         }
  13.     } else
  14.     {
  15.         cout << "File does not exist.  Expecting /etc/hostname.  Please fix program if you are not running a debian based distro.  Or just be lazy and create this file."
  16.                 << endl;
  17.     return ""; // Returns 1 to the operating system
  18.  
  19.     }
  20.     myReadFile.close();
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement