hi all,
I am trying to figure out how to read from a file, ifstream reader reading string next.... if next is a digit then add it to total... and cout total.. please indicate what went wrong. thank you.
# include <iostream>
# include <fstream>
# include <cstring>
# include <string>
# include <cctype>
using namespace std;
int main()
{
ifstream reader;
reader.open("num.txt");
string next;
double total=0;
bool digit =true;
while(reader>>next)
{
if(!isdigit(next))
{
double x= atof(next);
total+=x;
}
}
reader.close();
cout<<total;
return 0;
}