任何可用于确定字符串的STL /字符串函数都包含数字 [英] any STL/string function available for determing string contains numeric

查看:90
本文介绍了任何可用于确定字符串的STL /字符串函数都包含数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



他们用C ++提供的任何单一功能都可以确定

字符串

包含数值。

值cabn为十六进制,整数,浮点数。即1256,即1256。 ,123.566, ,

" 0xffff" ,它也可以包含零


Is their any single fuction available in C++ that can determine that a
string
contains a numeric value.
The value cabn be in hex, int, float. i.e. "1256" , "123.566" ,
"0xffff" , It can also contain zero

推荐答案

ni ********** @ st.com 写道:

他们在C ++中是否有任何单一功能这可以确定一个

字符串

包含一个数值。

值cabn是十六进制,整数,浮点数。即1256,即1256。 ,123.566, ,

" 0xffff" ,它还可以包含零
Is their any single fuction available in C++ that can determine that a
string
contains a numeric value.
The value cabn be in hex, int, float. i.e. "1256" , "123.566" ,
"0xffff" , It can also contain zero



编号你必须尝试其中一个C库数字转换

函数对字符串''内容。


-

Ian Collins。

No. You would have to try one of the C library numeric conversion
functions on the string''s contents.

--
Ian Collins.


甚至没有(strtoul,strtod )不可能因为strtoul要求

base(十六进制为16,十进制为10)

和我的字符串可以包含无效格式为0xffff12yzz或者

" 0xaa_AMERICA"或美国或美国。或者0xffff

我只是想检查一下可能的数值.....

它的内容对我来说无关紧

Ian Collins写道:
No even that(strtoul, strtod) would not be possible as strtoul ask for
base(16 for hex, 10 for dec)
and my string can containg a non valid format as "0xffff12yzz" or
"0xaa_AMERICA" or "AMERICA" or "0xffff"
I just want to check for the rigth possible numeric value.....
Its content does not matter to me
Ian Collins wrote:
ni ******* ***@st.com 写道:

他们用C ++提供的任何单一功能都可以确定

string

包含一个数值。

值cabn为十六进制,整数,浮点数。即1256,即1256。 ,123.566, ,

" 0xffff" ,它也可以包含零
Is their any single fuction available in C++ that can determine that a
string
contains a numeric value.
The value cabn be in hex, int, float. i.e. "1256" , "123.566" ,
"0xffff" , It can also contain zero



编号你必须尝试其中一个C库数字转换

函数对字符串'' s内容。


-

伊恩柯林斯。

No. You would have to try one of the C library numeric conversion
functions on the string''s contents.

--
Ian Collins.


ni ****** **** @st.com 写道:

即使那个(strtoul,strtod)也不可能因为strtoul要求

base(16为十六进制,10为dec)

和我的字符串可以包含无效格式为0xffff12yzz或者

" 0xaa_AMERICA"或美国或美国。或者0xffff

我只是想检查一下可能的数值.....

它的内容对我来说无关紧

Ian Collins写道:
No even that(strtoul, strtod) would not be possible as strtoul ask for
base(16 for hex, 10 for dec)
and my string can containg a non valid format as "0xffff12yzz" or
"0xaa_AMERICA" or "AMERICA" or "0xffff"
I just want to check for the rigth possible numeric value.....
Its content does not matter to me
Ian Collins wrote:

> ni * *********@st.com 写道:

>>他们在C ++中可用的任何单一功能是否可以确定
字符串
包含数值。
值cabn为十六进制,整数,浮点数。即1256,即1256。 ,123.566, ,
0xffff ,它也可以包含零
>>Is their any single fuction available in C++ that can determine that a
string
contains a numeric value.
The value cabn be in hex, int, float. i.e. "1256" , "123.566" ,
"0xffff" , It can also contain zero



如何将字符串输出到字符串流然后

尝试看了一个双?如果它成功读取并且

流中没有剩余任何字符,则它是一个

数字。我不确定这是否适用于十六进制数字

但是你可以尝试读一个整数作为副检查。


HTH,

- J.

How about outputting the string to a stringstream and then
trying to read a double? If it reads sucessfully and the
stream does not have any characters left in it, it is a
number. I''m not sure if this will work for hex numbers
though, but you might try reading an integer as a side-check.

HTH,
- J.


这篇关于任何可用于确定字符串的STL /字符串函数都包含数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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