Accessing members of an array of structures in C++
<p>Working through C++ Primer Plus and am trying to cin data to a dynamically allocated array of structures. One of the items is a char array. How do I write to these struct members? Posting code of my wrong attempt so you can see what I'm trying to do.</p>

<pre><code>    #include &lt;iostream&gt;
using namespace std;

struct contributions
{
    char name[20];
    double dollars;
};

int donors;

int main()
{
    cout &lt;&lt; "How many contributors will there be?\n";
    cin &gt;&gt; donors;
    contributions * ptr = new contributions[donors];
    for(int i = 0; i &lt;= donors; i++)
    {
        cout &lt;&lt; "Enter donor name #" &lt;&lt; i+1 &lt;&lt; ": \n";
        cin &gt;&gt; ptr-&gt;contributions[i].name;
        cout &lt;&lt; "Enter donation amount: \n";
        cin &gt;&gt; ptr-&gt;contributions[i].dollars;
    }
</code></pre>

<p>Thanks in advance!</p>
