Why does C++ read values wrong from txt files?

Viewed 862

I have made a program that reads value from txt file "database.txt", but output is wrong when the number is three digit

ifstream myfile("database.txt");
int broj_rijeci = 0;
if (myfile.is_open())
{
    while (getline(myfile, line))
    {
        if (line.at(0) == '[')
        {
            int i = line.length() - 2;
            int brojac = 0;
            system("pause");
            while (line.at(i) != line.at(0))
            {
                input = line.at(i);
                ascii_convert(input);
                broj_rijeci = broj_rijeci + input * pow(10, brojac);
                i--;
                brojac++;
            }
        }
    }
    myfile.close();
}
else cout << "Unable to open file";

and my database looks like this:

[311]

output is "310"

2 Answers
Related