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:
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.