I wanna make a config.ini file for my program that holds settings. How do you load an ini file in c++?
Printable View
I wanna make a config.ini file for my program that holds settings. How do you load an ini file in c++?
You use GetPrivateProfileString, just like you would in any other language.
C++ Code:
#include <windows.h> #include <iostream> int main() { // make sure that your buffer is large enough to hold // all the characters... the return value of GetPrivateProfileString // is the number of characters read. // the number '32' below is supposed to be in brackets, but the // forum highlighting breaks it. char buffer[32]; GetPrivateProfileString("section", "key", "default value", buffer, sizeof(buffer), "myFile.ini"); std::cout << "the value key=" << buffer << std::endl; return 0; }