Re: [Boost-users] Reading & Parsing an .ini input file using BOOST... ..!!

493 views
Skip to first unread message

Edward Diener

unread,
Oct 22, 2013, 8:42:11 PM10/22/13
to boost...@lists.boost.org
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.


_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Gordon Woodhull

unread,
Oct 22, 2013, 9:37:03 PM10/22/13
to boost...@lists.boost.org, boost...@lists.boost.org

Rahul Mathur

unread,
Oct 22, 2013, 7:52:08 PM10/22/13
to bo...@lists.boost.org, boost-i...@lists.boost.org, boost...@lists.boost.org

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?


 

Any clue?

Rahul Mathur

unread,
Oct 22, 2013, 9:01:03 PM10/22/13
to boost...@lists.boost.org, eldi...@tropicsoft.com
Let me tell you, w/o knowing characteristics about .ini file I manually created a input.ini file like an oridinary .txt or .log file and thought to try if it can be parsed entirely like normal file. Let me know, if I can manually write in .ini file as one of my READ file where I try READING entire LINE until end rather in "key, value" of .ini format.

Also, what could be the best and fastest way to large (~ 5KB) files on Linux with GNU compilers and Boost-v1.54. Is memory-mapped files the fastest way or iostream or boost.spirit?

Nat Goodspeed

unread,
Oct 23, 2013, 11:02:55 AM10/23/13
to boost...@lists.boost.org
On Tue, Oct 22, 2013 at 9:01 PM, Rahul Mathur <sri...@gmail.com> wrote:

Also, what could be the best and fastest way to large (~ 5KB) files on Linux with GNU compilers and Boost-v1.54. Is memory-mapped files the fastest way or iostream or boost.spirit?

You must have intended to write different units. 5KB isn't large.

Rahul Mathur

unread,
Oct 24, 2013, 9:28:42 PM10/24/13
to boost...@lists.boost.org
Thanks all. I was able to make out. Sometimes exploring C (strtok) also works well.


Reply all
Reply to author
Forward
0 new messages