Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string Linux::getHostName()
- {
- string host = "";
- ifstream myReadFile;
- myReadFile.open("/etc/hostname");
- if (myReadFile.is_open())
- {
- while (!myReadFile.eof())
- {
- myReadFile >> host;
- return host;
- }
- } else
- {
- 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."
- << endl;
- return ""; // Returns 1 to the operating system
- }
- myReadFile.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement