boost foreach库的例子

来源:互联网 发布:力控如何加密源码授权 编辑:程序博客网 时间:2024/05/23 23:46
  1. #include <boost/foreach.hpp>
  2. #include <string>
  3. #include <iostream>
  4. #include <vector>
  5. #include <list>
  6. #include <deque>
  7. #include <boost/array.hpp>
  8. int main(int argc,char* argv[])
  9. {
  10.   std::string test = "hello";
  11.   BOOST_FOREACH(char it,test)
  12.   {
  13.     std::cout<<it<<std::endl;
  14.   }
  15.   int int_array[] = {1,1,2,3,5,6,6,7,9};
  16.   BOOST_FOREACH(int i, int_array)
  17.   {
  18.     std::cout<<i<<std::endl;
  19.   }
  20.   std::vector<std::string> str_vector;
  21.   str_vector.push_back("hello,C++");
  22.   str_vector.push_back("boost foreach");
  23.   BOOST_FOREACH(std::string iter, str_vector)
  24.   {
  25.     std::cout<<iter<<std::endl;
  26.   }
  27.   boost::array<std::string,3> str_array;
  28.   str_array[0] = "this is way";
  29.   str_array[1] = "please my love";
  30.   BOOST_FOREACH(std::string iter, str_array)
  31.   {
  32.     std::cout<<iter<<std::endl;
  33.   }
  34.   return 0;
  35. }
原创粉丝点击