Nowe posty

Autor Wątek: Catch przychwytuje wyjątek mimo że wartość do sprawdzenie jest poprawna  (Przeczytany 738 razy)

KelThuzad

  • Gość
#include "my_file.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdexcept>

int main()
{
    my_file file( "dane.txt" );
    if ( file.is_file_opened() )
    {
        std::cerr << "Plik nie istnieje" << std::endl;
//        return 1;
    }
    if ( file.is_file_empty() )
    {
        std::cerr << "Plik jest pusty" << std::endl;
//        return 1;
    }
    try
    {
        double budget = std::stod( file.add_budget() );
    }
    catch ( std::invalid_argument)
    {
        std::cerr << "Dane w pliku nie są liczbami" << std::endl;
    }

    std::cout << "budrzet na starcie wynosi: " << std::setprecision(2) << budget << std::endl;
    return 0;
}
Wiem że w budget jest 800 więc czemu dostaje invalid_argument?