从文本文件读取变量 [英] Reading variables from text file

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

问题描述

我在使用c ++时遇到问题,希望这里的专家能对我有所帮助.

I have a problem in c++, and I hope that some expert here could help me.

问题是,有一个.txt文件,其中包含一些信息.我想编写一个使用此信息的程序.

the problem is, there is a .txt file, that has some information. I want to write a program that uses this information.

.txt文件将如下所示:

the .txt file will be like this:

variable 1: 711   
variable 2: [8 5 6 11]  
variable 3: xyz zyx yyy

程序应该从文件中读取值,然后使用它们,不知道该怎么做?!

the program should read the values from the file and then use them, any idea how to do it ?!!

/ *更新* /

要做的是从文本文件中读取数值,仅读取变量的数值,然后在实际程序中使用这些值.

what should be done is to read from the text file the numerical values, only the numerical values of the variables, and then use these values in the real program.

例如,读取变量1的值并将其放入变量x,然后在程序中我们可以定义 int y = 7 * x;

for example the value of variable 1 is read and put to a variable x, then in the program we may define int y=7*x ;

我知道如何读取文件,但是我不知道如何读取变量的特定值.

I know how to read a file, but what I don't know is how to read specific values of the variables.

基本上,程序应读取文件,识别变量的名称,获取值,然后使用它.

非常感谢

推荐答案

看起来您想要一个类似配置的文件来存储一些信息以供程序使用.配置文件管理有多种实现方式(读取,检索,存储,保存).我坚持使用小巧方便的libconfig: http://www.hyperrealm.com/libconfig/ 它支持整数,浮点和布尔变量,还支持数组,列表和封闭部分.

Looks like you want to have some configuration-like file to store some information for your program to use. There are many implementations of config-files management (read, retrieve, store, save). I stick to small and convenient libconfig : http://www.hyperrealm.com/libconfig/ It supports integer, floating-point and boolean variables, and arrays, lists and enclosed sections also.

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

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