开发者

boost::format and European floating-point format

This code uses boost::format to read data from ascii files. The cust开发者_开发百科omer 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.


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜