RedSonja
RedSonja

Reputation: 430

boost::format and European floating-point format

This code uses boost::format to read data from ascii files. The customer has data in European format - 3,14159 - and I need to be able to read this too. In another function it uses sscanf and I could make it be European by using
setlocale(LC_NUMERIC, "German");
but this does not seem to impress boost at all.

Upvotes: 1

Views: 752

Answers (1)

Nordic Mainframe
Nordic Mainframe

Reputation: 28767

I don't now how you are using boost::format for reading either, but anyway: The locale for boost::format to use is specified as a parameter to the format constructor.Example:

#include <iostream>
#include <locale>
#include <boost/format.hpp>

int main()
{
    std::locale en("en_US.UTF-8");
    std::locale de("de_DE.UTF-8");

    std::cout << boost::format("pi~=%1%",en)%3.141 << std::endl;
    std::cout << boost::format("pi~=%1%",de)%3.141 << std::endl;
}

Upvotes: 2

Related Questions