双 - > C-String转换 [英] Double -> C-String conversion

查看:53
本文介绍了双 - > C-String转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在循环的每次迭代中,我需要将double值转换为

char *。简单的类型转换不起作用,所以我想使用

stringstreams。但是,在每次b / b
迭代之后,流必须被*清空*(我无法想到这样做的实用方法)。


干杯,

Matthias

-
$ b $bFür电子邮件Anweisung in der Adresse befolgen

During every iteration in a loop, I need to convert a double value into a
char*. Simple type-casting did not work, so I thought of using
stringstreams. However, the stream would have to be *emptied* after each
iteration (and I could not conceive of a practical way doing that).

Cheers,
Matthias
--
Für emails Anweisung in der Adresse befolgen

推荐答案

Der Andere写道:
Der Andere wrote:
在循环的每次迭代中,我需要将双值
转换为char *。简单的类型转换不起作用,所以我想到使用
stringstreams。


听起来好像你想要你的双重字符串表示。 char *是

不是字符串。它是指向char的指针,仅此而已,仅此而已。

然而,在每次迭代后,流必须被清空*(我无法想象一个实用的方法)这样做。)
During every iteration in a loop, I need to convert a double value
into a char*. Simple type-casting did not work, so I thought of using
stringstreams.
Sounds as if you want a string representation of your double. A char* is
not a string. It''s a pointer to char, nothing less, nothing more.
However, the stream would have to be *emptied* after each iteration
(and I could not conceive of a practical way doing that).




执行以下操作:


thestream.str("");



Do the following:

thestream.str("");


Der Andere写道:
Der Andere wrote:
在循环的每次迭代中,我需要将double值转换为
char *。简单的类型转换不起作用,所以我想到使用
stringstreams。但是,在每次重复之后,流必须被清空*(我无法想象这样做的实用方法)。


如何使用sprintf?


sprintf(p,"%lf",doubleval);

//记得在你这样做之前给p分配内存。


HTH
干杯,
Matthias
-
Für电子邮件Anweisung in der Adresse befolgen
During every iteration in a loop, I need to convert a double value into a
char*. Simple type-casting did not work, so I thought of using
stringstreams. However, the stream would have to be *emptied* after each
iteration (and I could not conceive of a practical way doing that).
How about using sprintf ?

sprintf(p, "%lf", doubleval);
// Remember to allocate memory to p before you do this.

HTH
Cheers,
Matthias
--
Für emails Anweisung in der Adresse befolgen



-

Karthik


------


人类请为我的电子邮件删除。


--
Karthik

------

Human Beings please ''removeme'' for my email.


Rolf Magnus写道:
Rolf Magnus wrote:
Der Andere写道:

Der Andere wrote:

在循环的每次迭代中,我需要将双值
转换为char *。简单的类型转换不起作用,所以我想使用
stringstreams。
During every iteration in a loop, I need to convert a double value
into a char*. Simple type-casting did not work, so I thought of using
stringstreams.



听起来好像你想要一个双字符串的字符串表示。 char *不是字符串。它是指向char的指针,仅此而已,仅此而已。


Sounds as if you want a string representation of your double. A char* is
not a string. It''s a pointer to char, nothing less, nothing more.

但是,在每次迭代后,流必须被*清空*(和我无法想象这样做的实用方法。)
However, the stream would have to be *emptied* after each iteration
(and I could not conceive of a practical way doing that).



执行以下操作:

thestream.str("");


Do the following:

thestream.str("");




另外:


thestream.str()。clear();



Alternatively:

thestream.str( ).clear( );


这篇关于双 - > C-String转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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