1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Rep Power

    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 = ""; // 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. #2
  3. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    in the perfect world
    Rep Power
    I do this for my comercial apps....

    Use special characters to find what the settings are. Assemble the data to a structure.

    [ and ] for group headings start and end
    = for the break between a value and a its identifier


    [EOF]//marks end of file

    strstr() will help.

    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

IMN logo majestic logo threadwatch logo seochat tools logo