Read from file, String to int

This assignment was due last Friday. I am supposed to read a set of numbers from a file. The numbers have $'s and ,'s, I need to take them out to get the sum of the numbers. Extra Credit: If I can calculate the sum exactly and put the $'s and ,'s back in. This is what I have so far:

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main(){
string money;
ifstream fin;
fin.open("file.txt");

if(!fin){
cout<<"Could not open file. Shutting down...";
return 0;
}

string temp;
int count=0, index=0;
while(getline(fin,money)){
if(isdigit(money[count])){
temp.append(1, money[count]);
count++;
index++;
}
else {
count++;
}
}
fin.close();
temp.resize(index);

for(int n=0; n<index; n++){
cout<<endl;
cout<<temp<<endl;
}

//float sum=0;
//sum+=money;
//cout<<sum;

return 0;
}

This is what I have in file.txt:

$1,245.79
$89.63
$3,234,765.99
$12.88
$7.57
$100.00
$567,890,123.33

Thank you for any help you can give me!
Topic archived. No new replies allowed.