C++ boost库教程(九):boost for循环

    xiaoxiao2023-11-14  158

    boost for循环提供了两个宏:

                         正向迭代 BOOST_FOREACH,

                         逆向迭代 BOOST_REVERSE_FOREACH

    使用时需要包含头文件

                          #include <boost/foreach.hpp>

    基本操作和C 11的 for类似,例如下面是C 11的for代码:

    int arr[5] = { 1, 3, 5,2,4 }; //C 11的for循环 for (int e : arr) { cout << e << " "; }

    boost的for示例代码如下:

    #include "stdafx.h" #include <boost/foreach.hpp> #include <iostream> #include <vector> using namespace std; using namespace boost; int main() { int arr[5] = { 1, 3, 5,2,4 }; //C 11的for循环 for (int e : arr) { cout << e << " "; } cout << endl; //boost的for循环 BOOST_FOREACH(auto e, arr) { cout << e << " "; } cout << endl; vector<
    最新回复(0)