Dynamically adding an object?
<hr>

<pre><code>#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;iomanip&gt;

using namespace std;

static int c;

class DAI   //DynamicArrayInput
{
public :
    void getCountry()
    {
    cout &lt;&lt; "Country : ";
    cin &gt;&gt; Country;
    }

    void putCountry()
    {
    cout &lt;&lt; Country &lt;&lt; endl;
    }
    static int putCount()
    {
    return count;
    }
private :
    static int count;
    char Country[30];
};



int main()
{
vector&lt; DAI &gt; A;
DAI B[3];
//DAI * B;

cout &lt;&lt; "Enter name of countries\n";
  for(int i=0; i &lt; 3; i++)
  {
        //THIS DOESN'T WORK
    /*
    c++;   //c is a static variable declared at top
    B = new DAI[sizeof(DAI) * c/sizeof(DAI)];
    GIVES WRONG OUTPUT :
    Enter name of countries
    Country : a
    Country : b
    Country : c
    Printing name of countries


    c
    size of vector A is 3
    vector after initialisation:

    */  
    A.push_back(B[i]);
    B[i].getCountry(); 
  }
  cout &lt;&lt; "Printing name of countries\n";
  for(int i=0; i &lt; 3; i++)
  {
    B[i].putCountry();
  }

cout &lt;&lt; "size of vector A is " &lt;&lt; A.size() &lt;&lt; "\
    \nvector after initialisation:" &lt;&lt; endl;

return 0;
}


**/*
CORRECT OUTPUT WITH LIMITED ARRAY SIZE = 3:
*Enter name of countries
 Country : a
 Country : b
 Country : c
 Printing name of countries
 a
 b
 c
 size of vector A is 3
 vector after initialisation:*
*/**
</code></pre>

<p>I am just learning and this is not my homework,
I dont want to be limited to any array size such as above but when i try to use the staements in the first for loop as mentioned it does not work
i mean this does not works      </p>

<pre><code>c++;   //c is a static variable declared at top
B = new DAI[sizeof(DAI) * c/sizeof(DAI)];  //B is a pointer of type class DAI 
</code></pre>

<p>My aim is to use arrays of objects i like dynamically so that i can input any number of countries I don't want to use something like B[3] with something known array size but i am unable to do.</p>

<p>Please guide me, help me.</p>
