Mercurial > topfetch++
view main.cpp @ 0:bb144f2c5a3b
initial commit
| author | Yasuri <yasuri@charliesmp.net> |
|---|---|
| date | Sun, 04 Oct 2026 13:36:00 -0500 |
| parents | |
| children | 841975e638f2 |
line wrap: on
line source
#include <iostream> #include <fstream> #include <sstream> #include <iomanip> int main() { std::string myText; std::ifstream Meminfo("/proc/meminfo"); std::string uptimeText; std::ifstream Uptime("/proc/uptime"); std::string distro; std::ifstream OsRelease("/etc/os-release"); long total = 0; long available = 0; while (std::getline (Meminfo, myText)) { std::istringstream ss(myText); std::string name; long value; ss >> name >> value; if (name == "MemTotal:") { total = value; } if (name == "MemAvailable:") { available = value; } } std::string osLine; while (std::getline(OsRelease, osLine)) { size_t pos = osLine.find('='); if (pos == std::string::npos) continue; std::string key = osLine.substr(0, pos); std::string val = osLine.substr(pos + 1); if (key == "PRETTY_NAME") { distro = val.substr(1, val.size() - 2); } } long timeup = 0; while (std::getline (Uptime, uptimeText)) { std::istringstream ss2(uptimeText); double uptime; ss2 >> uptime; timeup = uptime; } std::cout << std::fixed << std::setprecision(2); std::cout << "Used: " << (total - available) / (1024.0 * 1024.0) << " GB" << "/" << total / (1024.0 * 1024.0) << "GB" << std::endl; std::cout << "Uptime: " << "Hours: " << timeup / 3600 << " Minutes: " << (timeup % 3600) / 60 << std::endl; std::cout << "OS: " << distro << std::endl; Meminfo.close(); }
