|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Make a c++ program w/ config files ?
How would I go about doing this ? I dont think #include would work, as it would build it in at compile time. I need it to open a file and check the variables there everytime the program is run. The config file would be like
namesrv1 = "ns1.sitename.com"; // Comment namesrv2 = "ns2.sitename.com"; // Comment ipaddr = "68.60.32.457"; // Comment I need the C++ program to open it and translate this into std::string variables which can be used in the program. Any help would be appriciated. |
|
#2
|
|||
|
|||
|
I do this for my comercial apps....
Use special characters to find what the settings are. Assemble the data to a structure. ie [ and ] for group headings start and end = for the break between a value and a its identifier [IP_ADD] host=127.168.0.1 [EOF]//marks end of file strstr() will help. roughly Find the file size, alloc mem for the file, read whole file, close file, set char pointer to begining of buffer, read config file settings to struct, free file buffer memory
__________________
The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions. Frank Zappa |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Make a c++ program w/ config files ? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|