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


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(50);
            }
            return true;
        }
        catch (...) {
            if (!errorShown) {
                cout << endl;
                errorPos = GetCursorPosition();
                errorShown = true;
            }
            SetCursorPosition(errorPos.Y, errorPos.X);
            SPACEBACK(50);
            cout << "Ошибка! Введите число: ";
            s.clear();
        }
    }
}