array元素的比较 图片看不了?点击切换HTTP 返回上层
可以用任何比较运算符比较两个数组容器,只要它们有相同的大小,保存的是相同类型的元素,而且这种类型的元素还要支持比较运算符。示例如下:
1 2 3 4 5 6 7 8 | std::array< double ,4> these {1.0, 2.0, 3.0, 4.0}; std::array< double ,4> those {1.0, 2.0, 3.0, 4.0}; std::array< double ,4> them {1.0, 3.0, 3.0, 2.0}; if (these == those) std::cout << "these and those are equal." << std::endl; if (those != them) std::cout << "those and them are not equal." << std::endl; if (those < them) std::cout << "those are less than them." << std::endl; if (them > those) std::cout << "them are greater than those." << std::endl; |
不像标准数组,只要它们存放的是相同类型、相同个数的元素,就可以将一个数组容器赋给另一个。例如:
1 | them = those; |