|
Boost Users : |
Subject: Re: [Boost-users] Reading & Parsing an .ini input file using BOOST... ..!!
From: Gordon Woodhull (gordon_at_[hidden])
Date: 2013-10-22 21:37:03
> On Oct 22, 2013, at 8:42 PM, Edward Diener <eldiener_at_[hidden]> wrote:
>
>> On 10/22/2013 7:52 PM, Rahul Mathur wrote:
>> All,
>>
>>
>> Need small help. I have an "input.ini" input file which contains sample
>> values like â
>>
>>
>> ---
>>
>> App=| 5000 | 5001 | 0 | | | | 1BYTE |
>>
>> ---
>>
>>
>> Starting with word (viz. App), followed by equal sign, than data within
>> pipes (|) and blank space between two pipes ( | | ). Anything only between
>> two pipes is to be read.
>>
>>
>>
>> I am looking to parse this input file. After parsing, assign each data to
>> struct member type and than send this complete struct as socket.
>>
>>
>>
>> I am looking to use Boost property tree (or the needed one) and finally the
>> ASIO to send the complete filled struct as stream.
>>
>> I tried below code to read complete data and it worked but -
>>
>> ---
>> #include <iostream>
>> #include <boost/property_tree/ptree.hpp>
>> #include <boost/property_tree/ini_parser.hpp>
>> #include <boost/filesystem/fstream.hpp>
>>
>> int main()
>> {
>>
>> boost::property_tree::ptree pt;
>> boost::property_tree::ini_parser::read_ini("input.ini", pt);
>> std::cout << pt.get<std::string>("App") << std::endl;
>> }
>> ---
>>
>> But, how to read between pipes?
>
> Look at Boost tokenizer library. Or use standard regex or Boost regex depending on what your compiler supports.
Or algorithm::split
http://www.boost.org/doc/libs/1_54_0/doc/html/boost/algorithm/split_idp54600576.html
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net