Alf P. Steinbach wrote:
* 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