#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <string>
#include <sstream>
#include <vector>
#include <cctype> //isdigit()

using namespace std;


void removeComma(fstream& f) {
	char c; int fp,i=0;
	while (f >> c && isdigit(c)) {
		++i;
		fp = f.tellg();
		f.seekp(fp - i);
		f << c;
		f.seekg(fp + i-1);
	}
}

double getNum(fstream& file, int fp) {
	char c;
	double d{ 0. };
	while (file >> c) {
		if (!isdigit(c) && c != ',')  { // && c != '.') { //Luis J. says, "use regex"
			file.seekg(fp-1);
			file >> d;
			return d;
		}
		if (c == ',') removeComma(file);
	}
	
}

int main() {
	char c;
	int fp, fp2;
	double sum{ 0. }, addend;
	fstream file("Test.txt", ios_base::in | ios_base::out);

	while (file >> c) {
		if (isdigit(c)) {
			fp = file.tellg();
			addend = getNum(file, fp-1);
			sum += addend;
			file.seekg(fp + (int)log10(addend) + 2);
		}
	}
	cout << "\nThe sum of the nums is " << sum;
	cin.get();
	
	/*cout << file.tellg();
	file.seekg(3);
	cout << '\n' << file.tellg();
	file.seekp(5);
	file << '0';*/
	file.close();
	cin.get();
}