字符串和数值之间的转换 [英] conversion between string and numerical value
问题描述
嗨
i需要一种快速的方法来进行大量的转换,即
字符串和数值(整数,浮点数,双数......),并且
boost :: lexical_cast没用,因为它运行了很长时间,
(比相应的C函数慢约60倍)
这对我的程序来说太贵了。
有什么方法([模板]库?)快速安全地做到这一点,
好吗?
(旧的C风格功能不合适)
Aman JIANG写道:
i需要一种快速的方法来进行大量的转换,即
字符串和数值(整数,浮点数,双数......)和
boost :: lexical_cast没用,因为它运行了很长时间,
(比相应的C函数慢约60倍)
它是'我的程序太贵了。
所以,使用C函数。
有什么办法([模板]库?)快速安全地做到这一点,
好吗?
我什么都不知道,但你应该相对轻松地滚动
你自己,不是吗?
(旧的C风格功能不合适)
为什么?
V
-
请在通过电子邮件回复时删除资金''A'
我没有回复顶部-posted回复,请不要问
Aman JIANG< Am ******* @ gmail.comwrites:
嗨
i需要一种快速的方法来进行大量的转换,即
字符串和数值(整数,浮点数,双精度) ......)和
boost :: lexical_cast没用,因为它运行了很长时间,
(比相应的C函数慢约60倍)
这对我的程序来说太贵了。
有什么办法([模板]库?)快速安全地完成这项工作,
拜托?
(旧的C风格功能不合适)
如何 :
#v +
std :: string toString(long value){
char buffer [100];
sprintf(buffer," %ld",value);
返回std :: string(缓冲区);
}
std :: string toString (unsigned long value){
char buffer [100];
sprintf(buffer,"%lu",value);
return std :: string(buffer);
}
long atol(std :: string str){return atol(str.c_str()); } $ / $
double atof(std :: string str){return atof(str.c_str()); }
#v-
这是C ++可以。
-
祝你好运,_ _
.o。 | Serenly Enlightened Majesty of o'',=。/`o
..o |计算机科学,Michalmina86 Nazarewicz(oo)
ooo + - < mina86 * tlen.pl> ---< jid:mina86 * chrome.pl> - ooO - (_) - Ooo--
9月20日,12月47日,Victor Bazarov < v.Abaza ... @ comAcast.netwrote:
(旧的C风格函数不合适)
为什么?
因为它的风格,它不支持wchar_t,模板等等
on ...
hi
i need a fast way to do lots of conversion that between
string and numerical value(integer, float, double...), and
boost::lexical_cast is useless, because it runs for a long time,
(about 60 times slower than corresponding C functions)
it''s too expensive for my program.
is there any way([template] library?) to do this fast and safely,
please ?
(old C-style functions is unbecoming)
Aman JIANG wrote:i need a fast way to do lots of conversion that between
string and numerical value(integer, float, double...), and
boost::lexical_cast is useless, because it runs for a long time,
(about 60 times slower than corresponding C functions)
it''s too expensive for my program.So, use the C functions.
is there any way([template] library?) to do this fast and safely,
please ?I don''t know of any, but should be relatively easy for you to roll
your own, no?
(old C-style functions is unbecoming)Why?
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
Aman JIANG <Am*******@gmail.comwrites:
hi
i need a fast way to do lots of conversion that between
string and numerical value(integer, float, double...), and
boost::lexical_cast is useless, because it runs for a long time,
(about 60 times slower than corresponding C functions)
it''s too expensive for my program.
is there any way([template] library?) to do this fast and safely,
please ?
(old C-style functions is unbecoming)How about:
#v+
std::string toString(long value) {
char buffer[100];
sprintf(buffer, "%ld", value);
return std::string(buffer);
}
std::string toString(unsigned long value) {
char buffer[100];
sprintf(buffer, "%lu", value);
return std::string(buffer);
}
long atol(std::string str) { return atol(str.c_str()); }
double atof(std::string str) { return atof(str.c_str()); }
#v-
It''s C++ all right.
--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o'' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>---<jid:mina86*chrome.pl>--ooO--(_)--Ooo--
On 9 20 , 12 47 , "Victor Bazarov" <v.Abaza...@comAcast.netwrote:(old C-style functions is unbecoming)
Why?because its style, it doesn''t support wchar_t, and template and so
on...
这篇关于字符串和数值之间的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!