且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Re:帮助在控制台输出上向逗号添加逗号

更新时间:2023-12-06 17:11:22

4月11日,11:32,James Kanze< james.ka ... @ gmail.comwrote:
On 11 Apr., 11:32, James Kanze <james.ka...@gmail.comwrote:

4月11日上午6:48,Jerry Coffin< jerry.cof ... @ gmail.comwrote :
On Apr 11, 6:48 am, Jerry Coffin <jerry.cof...@gmail.comwrote:

4月1日凌晨2:42,James Kanze< james.ka ... @ gmail.comwrote:

[ ...]
On Apr 1, 2:42 am, James Kanze <james.ka...@gmail.comwrote:
[ ... ]

我也会解释为什么do_grouping返回一个带二进制值的字符串

值,除了我不能自己想出那个;它只是

的确如此。
I''d also explain why do_grouping returns a string with binary
values, except that I can''t figure that one out myself; it just
does.



我不确定你指的是什么:它返回一个

字符串,或者它使用二进制值, 或两者。

I''m not sure which you''re referring to: that it returns a
string, or that it uses binary values, or both.



两者的组合。


The combination of the two.


使用二进制值使它们独立于字符
使用
编码。由于语言环境应该封装

这样的字符编码之类的东西,让它依赖于

字符编码会破坏目的。

使用字符串而不是指向const char的指针有点

更难以确定。我怀疑只是有人认为我们正在设计这个很酷的字符串类,为什么不使用

呢?
Using binary values makes them independent of the character
encoding used. Since the locale is supposed to encapsulate
such things as the character encoding, having it depend on the
character encoding would sort of defeat the purpose.
Using a string instead of a pointer to const char is a bit
harder to be certain about. I suspect it was just somebody who
thought "we''re designing this cool string class, why not use
it?"



* IF *在这里使用容器是合适的,那个容器

将是std :: vector<>,而不是std ::串。 *返回的内容

不是字符串,而是数组。 *将它称为字符串只是

混淆。


可以说,给定使用它应该是C中的int const *。

显然,使它成为char const *节省一些空间(因为没有人

将有超过127的千分之几),但是

我们''这里只说几个字节。 *但很明显

在C中,返回的是一个数组,而不是一个字符串。


在所有情况下,我都可以我真的想象一下它不会是一个不变的情况。 *类似于:


* * char const _thousands_sep [] = {3,0};


所以即使在C ++中,我也是d已经使用char const *或int

const *。 *(可能是char const *,认为这可能会允许重新使用某些C实现。)


*IF* it is appropriate to use a container here, that container
would be std::vector<>, not std::string. *What is being returned
is not a string, it is an array. *Calling it a string is just
obfuscation.

Arguably, given the use, it should have been an int const* in C.
Obviously, make it char const* saves some space (since no one
will ever have a thousands separation of more than 127), but
we''re talking here of only a couple of bytes. *But it is clear
that in C, what is being returned is an "array", not a string.

In all cases, I can''t really imagine a case where it wouldn''t be
a constant. *Something like:

* * char const _thousands_sep[] = { 3, 0 } ;

So even in C++, I''d have gone with either char const* or int
const*. *(Probably char const*, with the idea that this might
allow reusing some of the C implementation.)


使用容器(字符串或指向char的指针,允许

多个值,而不是

返回的单个字符,其他成员如do_thousands_sep和do_decimal_point是

因为它支持不同的分组宽度。

例如,你可以让第一组包含两个

数字,其余包含三位数。我不确定

谁使用它,但鉴于它与其他

成员的区别,我很确定有人一定认为它是

真的需要。
Using a container (string or pointer to char) that allows
multiple values, as opposed to the single char returned by
other members like do_thousands_sep and do_decimal_point is
because it supports different grouping widths.
For example, you could have the first group contain two
digits, and the remainder contain three digits. I''m not sure
who uses this, but given its difference from the other
members, I''m pretty sure somebody must have thought it was
really needed.



我知道这件事。 *我个人并不知道任何具有

这种分组的语言环境,但我似乎记得有人含糊地说

,其中一个存在使用4,2,0;或类似的东西。 *(

当然,这可能是一个过早的通用性的情况。*但是在一个

标准中,你不能回头让它更通用如果需要

以后出现。)


I''m aware of this. *I''m not personally aware of any locale with
such a grouping, but I seem to remember someone vaguely saying
that one existed using 4, 2, 0; or something like that. *(Of
course, it may be a case of premature genericity. *But in a
standard, you can''t go back and make it more generic if the need
later arises.)

http://en.wikipedia.org/wiki/Thousan...ands_separator

给出答案。

/ Peter

http://en.wikipedia.org/wiki/Thousan...ands_separator
gives the answer.
/Peter


在文章< d5f63e5c-53bc-439f-9dbf-6c652cb1a3f2 @

8g2000hse.googlegroups.com>, ja ********* @ gmail.com 说...


[.. 。]
In article <d5f63e5c-53bc-439f-9dbf-6c652cb1a3f2@
8g2000hse.googlegroups.com>, ja*********@gmail.com says...

[ ... ]

使用字符串而不是指向const char的指针有点

难以成为一定的。我怀疑只是有人认为我们正在设计这个很酷的字符串类,为什么不使用

呢?
Using a string instead of a pointer to const char is a bit
harder to be certain about. I suspect it was just somebody who
thought "we''re designing this cool string class, why not use
it?"



* IF *在这里使用容器是合适的,那个容器

将是std :: vector<>,而不是std ::串。返回的内容

不是字符串,而是数组。将它称为字符串只是

混淆。


*IF* it is appropriate to use a container here, that container
would be std::vector<>, not std::string. What is being returned
is not a string, it is an array. Calling it a string is just
obfuscation.



真 - 我很确定这是一个历史问题。字符串

类是在标准化过程中相对较早添加的。

矢量模板直到_lot_之后才被添加。我怀疑当时添加了b $ b矢量,没有人倾向于重新设计区域设置来使用

它们 - 特别是因为这样做可能会延迟

标准相当长一段时间(一年不会让我感到惊讶......)


-

后来,

杰瑞。


宇宙是自己想象的虚构。

True -- I''m pretty sure that''s a historical matter though. The string
class was added relatively early in the standardization process. The
vector template wasn''t added until a _lot_ later. I suspect by the time
vector was added, nobody had the inclination to redesign locales to use
them -- especially since doing so probably would have delayed the
standard by quite a while (a year wouldn''t surprise me at all...)

--
Later,
Jerry.

The universe is a figment of its own imagination.


On 11 avr,13 :19,peter koch< peter.koch.lar ... @ gmail.comwrote:
On 11 avr, 13:19, peter koch <peter.koch.lar...@gmail.comwrote:

4月11日,11:32,James Kanze< james .ka ... @ gmail.comwrote:
On 11 Apr., 11:32, James Kanze <james.ka...@gmail.comwrote:



[...]

[...]


我很清楚这一点。我个人并不知道任何这样的分组,但我似乎记得有人含糊地说

一个存在使用4,2,0;或类似的东西。 (

当然,它可能是一个过早的通用性的例子。但是在一个

标准中,如果需要的话,你不能再回头让它更通用了之后会出现
。)
I''m aware of this. I''m not personally aware of any locale with
such a grouping, but I seem to remember someone vaguely saying
that one existed using 4, 2, 0; or something like that. (Of
course, it may be a case of premature genericity. But in a
standard, you can''t go back and make it more generic if the need
later arises.)

http://en.wikipedia.org/wiki/Thousan...ands_separator

给出答案。
http://en.wikipedia.org/wiki/Thousan...ands_separator
gives the answer.



不是为什么值是字符串。它确实提出了一些有趣的问题,但是:根据具体情况,你可能需要

或者在小数点后可能不需要千位分隔符。
>
此外,法国常用的数千个分隔符是空格,根据上述内容,这是符合ISO建议的
。这意味着,

然而,你不能重读你写的东西。 (也许

不间断的空格?Unicode中的0xA0?)


-

James Kanze(GABI软件)电子邮件: ja*********@gmail.com

Conseils eninformatiqueorientéeobjet/

Beratung in objektorientierter Datenverarbeitung

9个地方Sémard,78210 St.-Cyr-l''coco,法国,+ 33(0)1 30 23 00 34

Not to why the value is a string. It does raise some
interesting issues, however: depending on the context, you may
or may not want thousand separators after the decimal point.

Also, the usual thousands separators in France are spaces, which
according to the above, is what ISO recommends. This means,
however, that you can''t reread what you''ve written. (Maybe
non-breaking spaces? 0xA0 in Unicode?)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l''école, France, +33 (0)1 30 23 00 34