用于确定整数字符串长度的函数 [英] Function to determine the length of an integer string

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

问题描述

是否有任何函数来确定整数字符串的长度?

Is there any function to determine the length of an integer string?

推荐答案

strlen给出字符串的长度而不管其是什么内容(即

整数或字符)

strlen gives the length of string irrespective of its content (ie.
integer or character)




coinjo写道:

coinjo wrote:
是否有任何函数来确定整数字符串的长度?
Is there any function to determine the length of an integer string?




什么是整数字符串?


std :: string有一个返回其长度的函数。


如果你有一个任何整数类型的变量,你可以转过

数它使用stringstream表示为一个字符串(你甚至可以通过使用

适当的流操作符来选择十进制,十六进制或八进制表示)。一旦你完成了,你可以询问

字符串有多长。


如果这些都没有帮助,请发布一些代码来展示什么你正试图

做。


Gavin Deane



What is an integer string?

std::string has a function that returns its length.

If you have a variable of any of the integer types, you can turn the
number it represents into a string using a stringstream (you can even
choose decimal, hexadecimal or octal representation by using the
appropriate stream manipulators). Once you''ve done that, you can ask
the string how long it is.

If none of that helps, post some code to show what you are trying to
do.

Gavin Deane



coinjo写道:

coinjo wrote:
是否有任何函数来确定整数字符串的长度?
Is there any function to determine the length of an integer string?




采取的对数值(向下舍入为整数)然后添加

一。


注意,logrithm的基数必须与用于
的基数相匹配
代表价值。例如,如果数字是100十进制,

等式将是:


Log10(100)+1 = 3

所以100有3位十进制数字。


格雷格



Take the logrithm of the value (rounded down to an integer) then add
one.

Note that the base of the logrithm has to match the base used to
represent the value. For example, if the number is 100 decimal, the
equation would be:

Log10(100)+1 = 3

so 100 has 3 digits as a decimal number.

Greg


这篇关于用于确定整数字符串长度的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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