boost-foreach

Parsing JSON with boost property tree

一笑奈何 提交于 2019-12-05 02:33:59
I'm building an application that gets movie information from themoviedb.com. The information is provided in a JSON file. I'm trying to store the information using boost property tree. But There is a little problem. I illustrate the problem by the following code: #include <vector> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> #include <boost/foreach.hpp> using namespace std; using boost::property_tree::ptree; class single_t{ int sID; string sName; public: void setID(int ID){sID=ID;} int getID(){return sID;} void setName(string Name){sName=Name;} string

Iterate over all files in a directory using BOOST_FOREACH

ⅰ亾dé卋堺 提交于 2019-12-03 04:59:33
Can you iterate over all files in a directory using boost::filesystem and BOOST_FOREACH? I tried path dirPath = ... int fileCount = 0; BOOST_FOREACH(const path& filePath, dirPath) if(is_regular_file(filePath)) ++fileCount; This code compiles, runs, but does not produce the desired result. nabulke You can iterate over files in a directory using BOOST_FOREACH like this: #include <boost/filesystem.hpp> #include <boost/foreach.hpp> namespace fs = boost::filesystem; fs::path targetDir("/tmp"); fs::directory_iterator it(targetDir), eod; BOOST_FOREACH(fs::path const &p, std::make_pair(it, eod)) { if

Boost 1.46.1, Property Tree: How to iterate through ptree receiving sub ptrees?

此生再无相见时 提交于 2019-11-28 22:15:41
问题 First of all I shall say that I think I got how it should be done but my code will not compile any way I try. I based my assumption on this official example of empty ptree trick. There you can find next line: const ptree &settings = pt.get_child("settings", empty_ptree<ptree>()); Which shows that it is (or should be) possible to get subptree out from ptree. So I assumed we could iterate thru ptree with something like BOOST_FOREACH in such manner: BOOST_FOREACH(const boost::property_tree:

How can I iterate over two vectors simultaneously using BOOST_FOREACH?

五迷三道 提交于 2019-11-27 13:28:11
I'd like to replicate the following with BOOST FOREACH std::vector<int>::const_iterator i1; std::vector<int>::const_iterator i2; for( i1 = v1.begin(), i2 = v2.begin(); i1 < v1.end() && i2 < v2.end(); ++i1, ++i2 ) { doSomething( *i1, *i2 ); } Iterating over two things simultaneously is called a "zip" (from functional programming), and Boost has a zip iterator : The zip iterator provides the ability to parallel-iterate over several controlled sequences simultaneously. A zip iterator is constructed from a tuple of iterators. Moving the zip iterator moves all the iterators in parallel.