Results 1 to 2 of 2

Thread: load .ini files?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    load .ini files?

    I wanna make a config.ini file for my program that holds settings. How do you load an ini file in c++?

  2. #2
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Re: load .ini files?

    You use GetPrivateProfileString, just like you would in any other language.


    C++ Code:
    1. #include <windows.h>
    2. #include <iostream>
    3.  
    4.  
    5. int main()
    6. {
    7.    // make sure that your buffer is large enough to hold
    8.    // all the characters... the return value of GetPrivateProfileString
    9.    // is the number of characters read.
    10.    // the number '32' below is supposed to be in brackets, but the
    11.    // forum highlighting breaks it.
    12.    char buffer[32];
    13.  
    14.    GetPrivateProfileString("section", "key", "default value", buffer, sizeof(buffer), "myFile.ini");
    15.  
    16.    std::cout << "the value key=" << buffer << std::endl;
    17.  
    18.    return 0;
    19. }
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width