Jake Reid
Jake Reid

Reputation: 85

Loading c++ source code from .txt file

void checkSettings()
{
    string STRING;
    ifstream infile;
    infile.open("C:\Users\Jakereid\Desktop\Settings.txt");
    while (!infile.eof) 
    {
        getline(infile, STRING);
        cout << STRING;
    }
    infile.close();

}

So I have a function called checkSettings, and it was just a long list of setmenu values:

menu.setValue(Tab_Menu, Menu_Custom2, 0);

It worked perfectly when it was in the source code under check settings, but what I want to do now is when the application starts is to load what ever is in the current settings.txt fileinto the check settings function. So what I want to do is to be able to have:

void checkSettings()
{
  Contents of the .txt file
}

I've tried following a few different tutorials but have had no luck. Thank you :)

Upvotes: 1

Views: 359

Answers (2)

Fantastic Mr Fox
Fantastic Mr Fox

Reputation: 33864

You cannot do this with C++ directly. C++ is a compiled language. What you can potentially do is call your settings file in a different language. For eg, there is a boost interface to call python scripts from c++.

You may also be able to use Lua.

Since these are not compiled languages, the code in your settings file can differ, and this will still work.

Upvotes: 3

merlin2011
merlin2011

Reputation: 75555

This will not work directly because C++ is a compiled language, and the settings file is different in each environment.

Instead, you should parse the settings file in your code and load the settings based on it.

Upvotes: 2

Related Questions