-1
#include <qapplication.h>
#include <qmainwindow.h>
#include "mainwindow.hpp"
#include "../RegisterOfErrors.hpp"
#include <clocale>

extern std::string* Error::DescriptionOfErrors;

int main (int argc, char *argv[])
{
   std::locale::global(std::locale("en_US"));
   setlocale(LC_ALL, "en_US");
   FILE *conf = fopen("dupa.txt", "r");
   float dupa;
   fscanf(conf, "%f", &dupa);
   printf("%f\n", dupa);
   Error::setDescriptionOfErrors();
   QApplication app(argc, argv);
   MainWindow window;
   window.show();
   return app.exec();
}

My default locales are "es_ES", so "," is a decimal point. It is my code. In the file "dupa.txt" is a number "1.0344" and it works correctly. However, deeper in the code I'm using the fann library, which is linked in g++ by "-ldoublefann" and read some data from files, and in this library works only ",".

godlark
  • 157
  • 7

1 Answers1

0

The problem was caused by Qt.

There is some code

#include "doublefann.h"
#include "fann_cpp.h"
#include <clocale>

int main() {
    setlocale(LC_ALL, "en_US");
    const int max_neurons = 20;
    const int neurons_between_reports = 1;
    const double desired_error = 0.0001;    
    FANN::neural_net* repetition_ann;
    repetition_ann = new FANN::neural_net();
    repetition_ann->create_shortcut(2, 2, 1);
    repetition_ann->cascadetrain_on_file("train.dat", max_neurons, neurons_between_reports, desired_error);
}

And this code works as I expect - It reads numbers, which have ".", from file "train.dat" ad prints numbers with ".". The difference between those cases: in the first case the similiar code is somewhere in qtapplication, this code is independent. Qt sets own locales, so the solution is adding a line: std::locale::global(std::locale("en_US")); and #include <QtCore>

godlark
  • 157
  • 7