C++ 如何将此行编辑为don';艾莫尔,这不是一个警告

C++ 如何将此行编辑为don';艾莫尔,这不是一个警告,c++,warnings,C++,Warnings,下面这行给了我一个警告: for (int i = 0; i < SpamBannListArray.size(); i++) 为了消除上述警告,我需要更改什么?您应该在for()循环头中使用unsigned类型声明I,因为SpamBannListArray.size()很可能返回一个unsigned类型: for (unsigned int i = 0; i < SpamBannListArray.size(); i++) // ^^^^^^^^ 如果您需要就地操作项,

下面这行给了我一个警告:

for (int i = 0; i < SpamBannListArray.size(); i++)

为了消除上述警告,我需要更改什么?

您应该在
for()
循环头中使用
unsigned
类型声明
I
,因为
SpamBannListArray.size()
很可能返回一个
unsigned
类型:

 for (unsigned int i = 0; i < SpamBannListArray.size(); i++)
   // ^^^^^^^^

如果您需要就地操作项,请使用
自动&

for()
循环头中,您应该使用
无符号
类型来声明
i
,因为
SpamBannListArray.size()
很可能返回一个
无符号
类型:

 for (unsigned int i = 0; i < SpamBannListArray.size(); i++)
   // ^^^^^^^^

如果您需要就地操作项目,请使用
auto&

您也可以使用auto来声明循环variable@kirikoumath事实上,不是用那种文字
0
。您必须至少写入
auto i=0u
size\u t
才是更正确的形式。让数据模型由实现决定。当然,您是正确的。事实上,尺寸是最好的option@CinderBiscuits取决于
SpamBannListArray
是什么。您还可以使用“自动”来声明循环variable@kirikoumath事实上,不是用那种文字
0
。您必须至少写入
auto i=0u
size\u t
才是更正确的形式。让数据模型由实现决定。当然,您是正确的。事实上,尺寸是最好的option@CinderBiscuits取决于
SpamBannListArray
是什么。不相关:如果
SpamBannListArray
是一个库容器,则很可能可以使用基于范围的for循环:
for(const auto&spamban:SpamBannListArray)
并消除一堆代码。顺便说一句,for range可能足够了:
for(/*const*/auto&e:SpamBannListArray)
无关:如果
SpamBannListArray
是一个库容器,那么很可能可以使用基于范围的for循环:
for(const auto&spamban:SpamBannListArray)
并消除一堆代码。顺便说一句,for范围可能足够了:
for(/*const*/auto&e:SpamBannListArray)
 for (size_t i = 0; i < SpamBannListArray.size(); i++)
for (auto item : SpamBannListArray) {
    // Do something with item
}