我有一个函数,我必须修改向量的值。在 C++ 中返回向量是一个好习惯吗?
功能一:
vector<string> RemoveSpecialCharacters(vector<string> words)
{
for (vector<string>::iterator it=words.begin(); it!=words.end(); )
{
if(CheckLength(*it) == false)
{
it = words.erase(it);
}
else{
++it;
}
}//end for
return words;
}
功能二:
void RemoveSpecialCharacters(vector<string> & words)
{
for (vector<string>::iterator it=words.begin(); it!=words.end(); )
{
if(CheckLength(*it) == false)
{
it = words.erase(it);
}
else{
++it;
}
}//end for
}