Загрузка данных


bool ReadDoubleWithESC(double& val) {
    std::string s;
    COORD errorPos = { 0, 0 };
    bool errorShown = false;

    while (true) {
        if (!ReadStringWithESC(s)) return false;
        if (s.empty()) continue;

        try {
            for (char& c : s) if (c == '.') c = ',';
            size_t pos = 0;
            val = std::stod(s, &pos);
            if (pos != s.length()) throw std::invalid_argument("Trailing characters");
            
            // Если ошибка была показана — стираем строку с ошибкой
            if (errorShown) {
                SetCursorPosition(errorPos.Y, errorPos.X);
                SPACEBACK(60);
            }
            return true;
        }
        catch (...) {
            if (!errorShown) {
                cout << endl;
                errorPos = GetCursorPosition();
                errorShown = true;
            }
            // Очищаем строку ошибки и выводим заново
            SetCursorPosition(errorPos.Y, 0);
            SPACEBACK(60);
            cout << "Ошибка! Введите число: ";
            s.clear();
        }
    }
}