解析文件 [英] parsing files

查看:85
本文介绍了解析文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我是新来的,我带着一个新手问题:


会是什么解析简单(配置)文件的最佳方法,如


config.txt:


keyA = value1,value2,value3,...

keyB = value1,value2,value3,...

....

(值(i)应转换为long或doulbe)


到目前为止,我使用了getopt(和strtod()一起使用

转换optarg)但作为我程序的输入得到更多

复杂的getopt

开始变得痛苦。


任何提示都很受欢迎。

欢呼,

elcorto

Hi

I''m new to the list and I''m coming with a newbie question:

What would be the best way to parse simple (config) files like

config.txt:

keyA=value1, value2, value3, ...
keyB=value1, value2, value3, ...
....
(the value(i) should be converted to long or doulbe)

Up to now I used getopt (together with strtod() and so on for
converting the optarg) but as the input for my program gets more
complicated getopt
is starting to get painful.

Any hints are appreciated.

cheers,
elcorto

推荐答案

2006年1月17日12:41:29 -0800,elcorto < EL ***** @ gmx.net>写道:
On 17 Jan 2006 12:41:29 -0800, "elcorto" <el*****@gmx.net> wrote:


我是新来的,我带着一个新手问题:

什么是解析简单(配置)文件的最佳方法,如

config.txt:

keyA = value1,value2,value3,...
keyB = value1,value2,value3,......
......
(值(i)应转换为long或doulbe)

到目前为止我使用了getopt(与strtod()等一起转换optarg)但是随着我程序的输入变得越来越复杂,getopt
开始变得痛苦。

任何提示都表示赞赏。
Hi

I''m new to the list and I''m coming with a newbie question:

What would be the best way to parse simple (config) files like

config.txt:

keyA=value1, value2, value3, ...
keyB=value1, value2, value3, ...
...
(the value(i) should be converted to long or doulbe)

Up to now I used getopt (together with strtod() and so on for
converting the optarg) but as the input for my program gets more
complicated getopt
is starting to get painful.

Any hints are appreciated.




试试这个:

comp.text.xml


- -

Bob Hairgrove
没有********** @ Home.com


我不打算使用XML。


欢呼,
elcorto

I''m not planning to use XML.

cheers,
elcorto


elcorto写道:
elcorto wrote:
I我是新来的,我带着一个新手问题:

什么是解析简单(配置)文件的最好方法,如

config.txt :

keyA = value1,value2,value3,...
keyB = value1,value2,value3,......
......
(价值( i)应该转换为long或doulbe)

到目前为止,我使用了getopt(与strtod()一起使用来转换optarg)但是作为我的程序的输入获取更多
复杂的getopt
开始变得痛苦。
I''m new to the list and I''m coming with a newbie question:

What would be the best way to parse simple (config) files like

config.txt:

keyA=value1, value2, value3, ...
keyB=value1, value2, value3, ...
...
(the value(i) should be converted to long or doulbe)

Up to now I used getopt (together with strtod() and so on for
converting the optarg) but as the input for my program gets more
complicated getopt
is starting to get painful.




读取一行(例如使用std :: geline)并搜索''=''符号,

然后将该线分成两等号。无论左边是什么

是你的名字。无论右边是什么,都是值列表。在逗号中拆分

值列表并以这种方式读出值。


这里是否存在C ++语言问题?


V



Read a line (using std::geline, for example) and search for the ''='' sign,
and then split the line in two at the equal sign. Whatever is to the left
is your name. Whatever is to the right is the list of values. Split the
list of values at the commas and read out the values that way.

Is there a C++ language question here somewhere?

V


这篇关于解析文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆