Is it possible to step through the members of a C++ struct?
<p>I want to step through the members of a C++ struct and print out their values. I can easily code this explicitly, but is there any way of doing it without actually knowing what's in the struct?</p>

<p>I suppose I'm looking for a C++ equivalent of C#'s foreach command.</p>

<p>Thanks for any help.</p>

<p>ADD: I'm doing something like this in C#. This code sets the struct members from an XML file read previously:</p>

<pre><code>[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
private struct SettingsStruct
{
    public uint nLength;
}

private void UpdateSettings()
{
    SettingsStruct settings = new SettingsStruct();

    foreach (FieldInfo fieldInfo in typeof(SettingsStruct).GetFields())
    {
        string settingName = "SETTING." + fieldInfo.Name.ToUpper();
        if (appSettings.Contains(settingName))
        {
            switch (fieldInfo.FieldType.FullName)
            {
                case "System.UInt32":
                    fieldInfo.SetValueDirect(__makeref(settings), uint.Parse((string)appSettings[settingName]));
                    break;
            }
        }
    }
}
</code></pre>
