.ini files

hello i have had trouble finding a ansure on google so im posting on this forum
how do you write a string to a .ini file
how do read read a section from a ini file and set it as a string
please do not give advice on .txt files
You can write to an .ini file just like a .txt file as far as I know, but you'd need to do some extra work to get the style right.

Have you tried Simpleini, as Duoas recommended?
http://code.jellycan.com/simpleini/

-Albatross :)
Last edited on
GetPrivateProfileString and WritePrivateProfileString:

http://msdn.microsoft.com/en-us/library/ms724353%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/ms725501%28v=VS.85%29.aspx

To write:

1
2
3
4
5
WritePrivateProfileStringA( "YourProgramName","keyname","value","C:/pathto/yourfile.ini" );

// writes
//  keyname=value
//  in the [YourProgramName] section of yourfile.ini 


To read:

1
2
3
4
5
6
7
char mybuffer[100];

GetPrivateProfileStringA( "YourProgramName","keyname","defaultvalue",
                           mybuffer,100,"C:/pathto/yourfile.ini");

// reads keyname from the [YourProgramName] section of yourfile.ini and puts it in mybuffer
//  if no keyname exists, "defaultvalue" is used instead 



EDIT: note I'm using the 'A' versions (WritePrivateProfileStringA and GetPrivateProfileStringA) because I'm using char arrays in the example.

See this for more: http://www.cplusplus.com/forum/articles/16820/
Last edited on
disch the lib wont work as i have windows vista 32 bit
Last edited on
What? The Windows API doesn't work with Windows? Did I miss something here?

-Albatross
Define "won't work"
o ssry i miss read the link it said 16 bit apps
i not 16 bit windows
It will still work. All that means is that .ini files are "outdated" and modern programs probably shouldn't be using them (according to that page, anyway).

You still can use them and the above functions will work just fine, though.
Topic archived. No new replies allowed.