snprintf的:简单的方法来强制。作为基数? [英] snprintf : simple way to force . as radix?
问题描述
我的计划是不正确的行为一台机器上,所以我就开始追捕这个错误,我发现那台机器上,snprintf的使用逗号(,),而不是一个。 (点)作为其他计算机(至少在我的经验)。
My program was not behaving correctly on one machine so I started to hunt for the bug, and I discovered that on that machine, snprintf uses a comma (,), not a . (dot) as 99% of other computers (at least in my experience).
应该不是这个标准化?
我使用的假定基数是一个图书馆。 (点),因此它不会与一个逗号正常工作
I am using a library that assumes that the radix is a . (dot) and so it does not work properly with a comma.
所以我的问题是,有一个简单的方法来强制点作为基数字符?我知道我可以只搜索和;一个点手动替换逗号,但肯定有一个更清洁的方式。
So my question is, is there a simple way to force the dot as the radix character? I know I could just search & replace the comma by a dot manually, but surely there is a cleaner way.
推荐答案
您应该可以使用的setlocale
- 功能使snprintf的使用来改变你的语言环境设置点。尝试将它设置为POSIX或C。 (的setlocale(LC_ALL,POSIX)
You should be able to change your locale-setting using the setlocale
-function to make snprintf use a dot. Try setting it to "POSIX" or "C". (setlocale(LC_ALL, "POSIX")
这篇关于snprintf的:简单的方法来强制。作为基数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!