如何处理未知长度的数组? [英] how to deal with arrays with unknown length?
问题描述
例如,在函数int a(int [] b)中,我想要处理
数组b的每个元素,但是b'的长度仍然未知那么我能做什么呢?
呢?
2006年8月29日20:24:29 - 0700 in comp.lang.c ++,Magcialking
< ma ******** @ 163.comwrote,
>例如,在函数int a(int [] b)中,我想要处理
数组b的每个元素,但是b'的长度仍然是未知的,那么什么我可以吗?
用C ++而不是C写它。
避免裸裸阵列。
你可能最终得到类似于:
int a(std :: vector< int& b)
否则,你必须传递元素的数量作为额外的
参数或其他东西。
David Harmon写道:
2006年8月29日20:24:29 -0700 comp.lang.c ++,Magcialking
< ma ******** @ 163.comwrote,
>例如,在函数int a(int [] b)中,我想要处理
数组b的每个元素,但是b的长度仍然未知,那么我能做什么呢?
用C ++而不是C写它。
避免裸裸阵列。
你可能最终得到类似于:
int a(std :: vector< int& b)
否则,你必须传递元素的数量作为额外的
参数,或其他什么。
更不用说用C ++而不是Java编写。
< blockquote>
" Magcialking" < ma ******** @ 163.comschrieb im Newsbeitrag
新闻:11 ********************* @ p79g2000cwp.googlegro ups.com ...
例如,在函数int a(int [] b)中,我想要每个元素
数组b要处理,但b'的长度仍然未知,那么什么可以
我
呢?
在C中,您将传递第二个参数中的元素数。你可以
也定义一个最后一项。值。或者您可以简单地猜测;)
for example,in the function "int a(int[] b)", I wanna every element of
array b to be dealt with, but b''s length remains unkown, so what can I
do?
On 29 Aug 2006 20:24:29 -0700 in comp.lang.c++, "Magcialking"
<ma********@163.comwrote,>for example,in the function "int a(int[] b)", I wanna every element of
array b to be dealt with, but b''s length remains unkown, so what can I
do?Write it in C++ instead of C.
Avoid bare naked arrays.
You might end up with something like:
int a(std::vector<int& b)
Otherwise, you have to pass the number of elements as an additional
argument, or something.
David Harmon wrote:On 29 Aug 2006 20:24:29 -0700 in comp.lang.c++, "Magcialking"
<ma********@163.comwrote,>for example,in the function "int a(int[] b)", I wanna every element of
array b to be dealt with, but b''s length remains unkown, so what can I
do?
Write it in C++ instead of C.
Avoid bare naked arrays.
You might end up with something like:
int a(std::vector<int& b)
Otherwise, you have to pass the number of elements as an additional
argument, or something.
Not to mention writing in C++ instead of Java.
"Magcialking" <ma********@163.comschrieb im Newsbeitrag
news:11*********************@p79g2000cwp.googlegro ups.com...for example,in the function "int a(int[] b)", I wanna every element
of
array b to be dealt with, but b''s length remains unkown, so what can
I
do?In C you would pass the number of elements in a 2nd argument. You can
also define a "last item" value. Or you can simply guess ;)
这篇关于如何处理未知长度的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!