向量结构 C++ [英] Structure of vectors C++
本文介绍了向量结构 C++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法使用单个语句一次清除向量结构?IE.结构体{向量字符串列表;矢量距离列表;}A;
is there a way to clear a structure of vectors at a time using a single statement ? i.e. struct AStruct { vector StringList; vector DistanceList; }A;
我想要使用单个语句的两个向量.
i want both the vectors using a single statement.
推荐答案
当然:
AStruct a;
// stuff
a = AStruct(); // clear it
不过,我可能会给自己一个函数:
However, I would probably give myself a function:
struct AStruct {
vector <string> StringList;
vector <string> DistanceList; }
void clear() {
StringList.clear();
DistanceList.clear();
}
};
然后你可以说:
AStruct a;
// stuff
a.clear(); // clear it
这可能更容易理解.
这篇关于向量结构 C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文