if(x.size()!= s)x.resize(s); [英] if(x.size() != s) x.resize(s);
问题描述
我想知道是否需要调整大小()以检查容器是否已经具有所需大小的
。
I wonder if resize() is required to check whether a container is
already of the desired size.
推荐答案
n.************@gmail。 com 写道:
我想知道是否需要调整大小()以检查容器是否已经具有所需大小的
。
I wonder if resize() is required to check whether a container is
already of the desired size.
是的,标准中规定的逻辑是
if(newSize size())
延伸
否则如果(newSize< size())
擦除
else
什么都不做。
-
Ian Collins。
Yes, the logic specified in the standard is
if( newSize size())
extend
else if( newSize < size())
erase
else
do nothing.
--
Ian Collins.
1月24日晚上7:15,Ian Collins< ian-n ... @ hotmail.comwrote:
On Jan 24, 7:15 pm, Ian Collins <ian-n...@hotmail.comwrote:
n.torrey.pi .. 。@ gmail.com写道:
n.torrey.pi...@gmail.com wrote:
我想知道是否需要resize()来检查容器是否是
已经达到了所需的大小。是的,标准中指定的逻辑是
I wonder if resize() is required to check whether a container is
already of the desired size.Yes, the logic specified in the standard is
if(newSize size())
extend
else if(newSize< size())
擦除
if( newSize size())
extend
else if( newSize < size())
erase
请注意,你不能保证得到任何回忆...特别是如果
容器是一个向量。
Note that you''re not guaranteed to get any memory back...especially if
the container is a vector.
n。************ @ gmail.com 写道:
我想知道是否需要resize()来检查容器是否已经具有所需大小的
。
I wonder if resize() is required to check whether a container is
already of the desired size.
这取决于你想要的行为。如果你想要的大小是什么,不管是什么,那么x.resize(s)就是你所需要的。这可能会添加
元素,删除元素或什么也不做,具体取决于当前的大小。
-
Alan Johnson
It depends on the what behavior you want. If you want the size to be s
no matter what, then x.resize(s) is all you need. This might add
elements, remove elements, or do nothing, depending on the current size.
--
Alan Johnson
这篇关于if(x.size()!= s)x.resize(s);的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!