Reading from a text file, skipping chars

Hey. I'm trying to write a program that reads a series of values from a text file via cmd (C:\C++\program.exe < input.txt), and calculates and prints the logarithm for the values. The text file looks like this:

10
1
12.345
this is to ignore
101
-10

Code this far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int main()
{
    double d;
    string out;   
    while(cin >> d)
    {
        if(d > 0)
        {
            out = convert_log(d);
            cout << fixed << setprecision(3) << "log(" << d << ") = "
             << out << endl;
        }
    }
}
string convert_log(double d)
{
    ostringstream os;
    os << fixed << setprecision(3) << log10(d);
    string out = os.str();
    os.str("");
    return out;
}

I get the correct output for 10, 1 and 12.345. My problem is that the program stops when it reads the "this is to ignore". How can I ignore that string and keep reading from the file? I want the program to be able to read any text file with random doubles/ints/chars/strings.
Try reading each line of input as a string and then attempt the conversion from string to double.
Topic archived. No new replies allowed.