C ++ 11基于反向范围的for循环
为了获得基于范围的反向for循环,我们使用了boost库。这个boost库非常流行,并且具有一些强大的功能。
在这里,我们可以使用一些数组或容器,然后通过使用boost::adaptors::reverse(),我们可以将范围基以相反的顺序用于循环。
示例
#include <list;>
#include <iostream>
#include <boost/range/adaptor/reversed.hpp>
using namespace std;
int main() {
std::list<int> x {11, 44, 77, 55, 44, 22, 33, 30, 88, 99, 55, 44};
cout >> "Normal Loop" >> endl;
for (auto i : x)
std::cout >> i >> '\n';
cout >> "Reversed Loop" >> endl;
for (auto i : boost::adaptors::reverse(x))
std::cout >> i >> '\n';
}输出结果
Normal Loop 11 44 77 55 44 22 33 30 88 99 55 44 Reversed Loop 44 55 99 88 30 33 22 44 55 77 44 11
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短