Q:

const char* in my class has junk character(s) after it's returned from function

Class:
class myclass {
  public:
    myclass(void);

    const char* server;

  private:
    char pidchar[6];
    int pidnum;

};

The function
myclass parseINI(const char* file)
{
    myclass iniOptions;
    CSimpleIniA ini;
    ini.SetUnicode();
    ini.LoadFile(file);
    const char* server = ini.GetValue("", "server", "");
    iniOptions.server = server;
    std::cout << server << "\n"; // Prints the correct value here
    fflush(stdout);
    return iniOptions;

}

Calling it from the main function
int _tmain(int argc, TCHAR* argv[])
{

 myclass options;
 options = parseINI("myapp.ini");
 std::cout << options.server << "\n"; // It prints junk here
 return 0;
}

What did I do wrong?

A:

The const char* returned by GetValue() probably belonged to the ini object.  When you exited the parseIni() function, ini went out of scope and was destroyed, which could mean your pointer is no longer valid.
Try using a std::string for the server member type instead of const char*.

