How to upgrade config file

C

Chinmoy Mukherjee

Hi All,
I have a config file as followings

[SERVER_DETAILS]
IP_ADDR=1.2.3.4
PORT=1290

[CLIENT_DETAILS]
IP_ADDR=1.2.3.5
PORT=1291

,etc now my requirement is to write a C++ program which can add a new
entry in the config file, delete existing entry from config file and
modify value of existing entry from the config file
Is there any easy way of solving this?

Regards,
Chinmoy
 
A

Alf P. Steinbach

* Chinmoy Mukherjee:
I have a config file as followings

[SERVER_DETAILS]
IP_ADDR=1.2.3.4
PORT=1290

[CLIENT_DETAILS]
IP_ADDR=1.2.3.5
PORT=1291

,etc now my requirement is to write a C++ program which can add a new
entry in the config file, delete existing entry from config file and
modify value of existing entry from the config file
Is there any easy way of solving this?

Question the requirement. Use a script language. Or, for C++, use the
platform's usual API for updating such config files.
 
B

BigBrian

Alf said:
* Chinmoy Mukherjee:
I have a config file as followings

[SERVER_DETAILS]
IP_ADDR=1.2.3.4
PORT=1290

[CLIENT_DETAILS]
IP_ADDR=1.2.3.5
PORT=1291

,etc now my requirement is to write a C++ program which can add a new
entry in the config file, delete existing entry from config file and
modify value of existing entry from the config file
Is there any easy way of solving this?

Question the requirement.

LOL. That's exactly what some people I work with do, when they're lazy
and don't want to write code.

Their are times when requirements need to be questioned. But on this
newsgroup the topic is the C++ language ( and not system design or
software engineering where requirements should be reviewed closely )
The question was "Is there any easy way of solving this ( assuming in
C++ )"? Avoiding the answer by suggesting changing the requirements
probably isn't how the OP though C++ experts would handle such a
question.

Here's my answer....
"Easy" is a relative term. It can be done in C++, but most people who
ask such questions probably wouldn't consider it easy. One project
that I work on supports config files similar to yours by defining data
structures to hold the data, it parses the file and fills these data
structures. There is also code to write the data structures back to
file. If your program doesn't need to use any of the info in the config
file, but only needs to change or add a value, you could use a C++
library which supports regular expressions to make the changes you need
to the file.

However, If I were asked to write something to only change the file (
and it wasn't required to be in C++ ), I would choose perl instead of
C++.

-Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top