reading ini file?

Started by
3 comments, last by ThePretender 21 years, 2 months ago
Is there some easy way to read a .INI file? I have written my own function to read/find whatever variable i need, however.... How do I set them?? My .ini file is set up like this [SECTION HEADER] <---worthless, just for my own orginization variable = x; somebool = true; somefloat = 6.0525f; [SECTION HEADER] <--- same as before go on ect, ect. Anyways, when I store variable = x into an array, how do i have it set that variable?? My function is this (if this is wrong setup, please tell me) bool INI::Input(char* variable, char* type) variable is the variable im looking for, and type is the type (float, bool, int, ect) anybody have some help?? Maybe an easier way?
Advertisement
you can overload Input for different types, like so:

// reads 'name' as a float
bool Input(string name, float& value);

// reads 'name' as an integer
bool Input(string name, int& value);

// reads 'name' as a string
bool Input(string name, string& value);

// reads 'name' as a boolean
bool Input(string name, bool& value);

etc.

[edited by - niyaw on January 31, 2003 11:38:53 PM]
I don''t know for sure, but wasn''t there an API for reading INI files? Or was it a special statement in Delphi?

Right, now I''m confused!

But why make an INI file? Isn''t writing in the Registry a little bit easier (when you know how to do it)?
Writing to the registry is similiar to INI files. I personally prefer INI-files but thats totally up to you...

INI-Files:
GetPrivateProfileString("Section", "Key", DefaultValue. etc..)

Registry:
GetProfileInt(....)


see MSDN for more info on that
for API based INI support, u do have the GetPrivateProfileInt/String functions. but i think they''re windows specific. for general support, u''re probably left to ur own devices

on registry settings, i guess its a preference. also, it is windows only and not everyone codes for windows. besides, the registry if not handled well can be like opening Pandora''s Box. if ppl can erase their harddisks by misuse of the IO functions, imagine wat can happen to Windows if ur registry manipulation code screws up. just a thought
- To learn, we share... Give some to take some -

This topic is closed to new replies.

Advertisement