简体   繁体   English

如何在C ++中使用集合向量?

[英]How to do the vector of sets in C++?

I can do a simple array of sets: set < char > * words = new set < char > [10] How I can do a vector of sets? 我可以做一个简单的集合数组: set < char > * words = new set < char > [10]我如何做一组集合? This results in a compiler error: vector < set< char >> v . 这会导致编译器错误: vector < set< char >> v Thank you for answers! 谢谢你的回答!

If vector < set< char >> v is exactly what you've got there (I hope you cut and pasted), you've run into one of the annoying little features of C++. 如果vector < set< char >> v正是你所拥有的(我希望你剪切和粘贴),你会遇到一个令人烦恼的C ++小功能。

Those >> look to you like two closing angle brackets for two templates. 那些>>看起来像两个模板的两个闭合尖括号。 They look like a right shift operator to the compiler. 它们看起来像编译器的右移运算符。 Change them to > > with a space in between. 将它们更改为> > ,中间有一个空格。

Fortunately, this is being addressed in the C++ standard that should be ratified this year. 幸运的是,这应该在今年应该批准的C ++标准中得到解决。 Unfortunately, you aren't working with a C++11-compliant compiler just now. 不幸的是,您刚才没有使用符合C ++ 11的编译器。

而不是'>>'尝试'>>'...就像这样:

vector<set<char> > testVect;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM