What fixed the problem for me was adding this line:
C(const char *s) {
std::locale::global(std::locale("C"));
std::fstream f(s);
double d;
f >> d;
std::cout << d;
f >> d;
std::cout << d;
}
I suspect that gtk might be modifiying locale itself after the application is launched so I have to correct it.