返回一个空向量 c++
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24175507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
return an empty vector c++
提问by user3369592
The requirement is that I need to search a vector to see if it contains the value passed in as the parameter. If the value exists in the vector, I return the vector. Else, I return an empty vector. I am not sure how to return an empty vector in c++. hope you could help me. my mimic.h:
要求是我需要搜索一个向量以查看它是否包含作为参数传入的值。如果该值存在于向量中,则返回该向量。否则,我返回一个空向量。我不确定如何在 C++ 中返回一个空向量。希望你能帮助我。我的模仿者.h:
vector<Pair> map;
my Pair.h:
我的 Pair.h:
Pair(){
}
~Pair(){}
string prefix;
vector<string> sufix;
Return vector function :
返回向量函数:
vector<string> Mimic::getSuffixList(string prefix){
int find=0;
for(int i =0; i < map.size(); i++)
{
if(map[i].prefix == prefix)
{
find =1;
return map[i].sufix; //sufix is a vector from a class called "Pair.h"
}
}
if(find==0)
{
//return an empty vector.
}
}