将整数转换为字符串? B计划? [英] Convert an integer to a string? Plan B?

查看:70
本文介绍了将整数转换为字符串? B计划?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http:// public。 research.att.com/~bs/b...#int-to-string


是否没有C库函数接受int并将其转换为它的

ascii表示? Bjarne在他的常见问题中显示的例子并不是非常便宜。

-

NOUN:1。遗嘱遗留给他人的金钱或财产。 2.从祖先或前任或过去那里下来的东西:b
宗教自由的遗产。 ETYMOLOGY:MidE legacie,副手办公室,来自OF,来自ML legatia的
,来自L legare,以及deute,遗赠。 www.bartleby.com/61/

解决方案

Steven T. Hatton写道:

http://public.research.att.com/~bs/b...#int-to-string

是否没有C库函数接受int并将其转换为
ascii表示? Bjarne在他的常见问题中显示的例子并不是非常方便。




sprintf


V

-

请通过邮件回复从我的地址删除资金


Steven T. Hatton写道:

http:// public .research.att.com / ~bs / b ... #int-to-string

是否没有C库函数可以获取int并将其转换为




Stroustrup提供的示例是最好的方法。比较:

http://www.parashift.com/c++-faq-lit....html#faq-39.2
http://www.parashift.com/c++-faq-lit....html #faq-39.3


正如FAQ所说,你可以使用C语言而不是C ++语言,但

后者应该是首选。


另见Boost'的lexical_cast。


干杯! --M


mlimber写道:


正如FAQ所说,你可以使用C工具而不是C ++但是
后者应该是首选。




然而,它并没有说出为什么C ++。方法应该是首选。

(是的,我知道可以将输出缓冲区传递给C函数的
.Don''这样做。)


C提供了非常好的转换功能。 C ++是指C ++。方法,

创建一个你扔掉的字符串流对象,非常昂贵。我永远不会用它。


-


Pete Becker

Roundhouse Consulting,Ltd。


http://public.research.att.com/~bs/b...#int-to-string

Is there no C library function that will take an int and convert it to its
ascii representation? The example Bjarne shows in his faq is not extremely
convenient.
--
NOUN:1. Money or property bequeathed to another by will. 2. Something handed
down from an ancestor or a predecessor or from the past: a legacy of
religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF,
from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/

解决方案

Steven T. Hatton wrote:

http://public.research.att.com/~bs/b...#int-to-string

Is there no C library function that will take an int and convert it to its
ascii representation? The example Bjarne shows in his faq is not extremely
convenient.



sprintf

V
--
Please remove capital As from my address when replying by mail


Steven T. Hatton wrote:

http://public.research.att.com/~bs/b...#int-to-string

Is there no C library function that will take an int and convert it to its
ascii representation? The example Bjarne shows in his faq is not extremely
convenient.



The example Stroustrup gives is the best way. Compare:

http://www.parashift.com/c++-faq-lit....html#faq-39.2
http://www.parashift.com/c++-faq-lit....html#faq-39.3

As the FAQ notes, you could use C facilities rather than C++, but the
latter should be preferred.

See also Boost''s lexical_cast.

Cheers! --M


mlimber wrote:


As the FAQ notes, you could use C facilities rather than C++, but the
latter should be preferred.



However, it doesn''t say why the "C++" approach should be preferred.
(Yes, I''m aware that it''s possible to pass too small an output buffer to
the C functions. Don''t do that.)

C provides perfectly good conversion functions. The "C++" approach,
creating a stringstream object which you then throw away, is extremely
expensive. I would never use it.

--

Pete Becker
Roundhouse Consulting, Ltd.


这篇关于将整数转换为字符串? B计划?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆