Untitled

mail@pastecode.io avatarunknown
plain_text
a month ago
862 B
1
Indexable
Never
#include <iostream>
#include <fstream>
#include <string>
#include <windows.h> // For Windows API functions

bool isHostsFileEmpty() {
    std::string hostsFilePath = "C:\\Windows\\System32\\Drivers\\etc\\hosts";
    std::ifstream file(hostsFilePath);
    
    if (!file.is_open()) {
        std::cerr << "Failed to open file: " << hostsFilePath << std::endl;
        return false;
    }
    
    std::string line;
    bool isEmpty = true;
    
    while (std::getline(file, line)) {
        if (!line.empty()) {
            isEmpty = false;
            break;
        }
    }
    
    file.close();
    return isEmpty;
}

int main() {
    if (isHostsFileEmpty()) {
        std::cout << "Hosts file is empty." << std::endl;
    } else {
        std::cout << "Hosts file is not empty." << std::endl;
    }
    
    return 0;
}