INI Files

This is a discussion on INI Files within the C++ Programming forums, part of the General Programming Boards category; Hello, I'm going to start working on a program that will save your preferences in a .ini form. I want ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155

    INI Files

    Hello,

    I'm going to start working on a program that will save your preferences in a .ini form. I want to follow the INI file standards, but I have no clue how I would parse this in a c++ program.
    Code:
    (test.ini)
    [header]
    variablename=value
    variablename2=anothervalue
    If someone could help, I would very much appreciate it.

    Thanks,

    Matt
    ~guitarist809~

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So the first line must contain the filename surrounded in (). Presumably you know the name of the filename you attempted to open, so you can check that it's right -- or you can ignore it if you don't care.

    Then I guess you need to read in "[header]".

    Then you read something=something else. You can use the three-parameter form of getline, using '=' for the delimiter. You had better know what all the possible things for the left side are; you then do a lot of if-else checks, or perhaps something more fancy if you have a lot of different left-hand sides; whatever the left side is, that tells you how to read the right-hand side.

    Repeat until tired or out of data.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Location
    USA::Colorado
    Posts
    155
    Actually, I dont need the (filename) thing, I don't know why I put that there

    But as for the getline idea, it sounds like it'll work! Thanks for the idea!
    ~guitarist809~

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    There's plenty of free INI file parsers out there, such as this one: http://ndevilla.free.fr/iniparser/

    I prefer not to reinvent the wheel unless I know I can make a better wheel.

    Quote Originally Posted by tabstop
    So the first line must contain the filename surrounded in ().
    Does it? I don't think I've seen many (or any?) INI files that do that.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by cpjust View Post
    Does it? I don't think I've seen many (or any?) INI files that do that.
    I have no idea. I just went from the example quoted.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Working with muliple source files
    By Swarvy in forum C++ Programming
    Replies: 1
    Last Post: 10-02-2008, 08:36 AM
  2. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 01:41 PM
  3. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. ini files
    By bigSteve in forum C Programming
    Replies: 1
    Last Post: 03-05-2002, 11:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21