title: C++ Dynamic Array of Structures User Input
body: <p>I'm trying to learn C++ on my own using Stephen Prata's "C++ Primer Plus 6th Edition. One of the chapter 5 exercises asks me to design a dynamic structure holding name and year of a number of cars. All this information is to be input by the user.
  My questions are:</p>
  
  <p>1) Can I use a string object instead of an array of char in the structure? If so, could you tell me how?</p>
  
  <p>2) How can I enable the user to input a name that consists of more than one word? I've been trying to use get(), getline() etc. but I just can't make it work. </p>
  
  <p>3) I know it is a simple programme but in what way could the code be improved?</p>
  
  <p>Thank you in advance. </p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  const int ArSize = 20;
  
  struct automobile
  {
      char name[ArSize];
      int year;
  };
  
  int main()
  {
  cout &lt;&lt; "How many cars do you wish to catalogue?\n";
  int number;
  cin &gt;&gt; number;
  
  automobile * car = new automobile[number];
  int n = 0;
  
  while (n &lt; number)
  {
      cout &lt;&lt; "Car #" &lt;&lt; n+1 &lt;&lt; ":\n";
      cout &lt;&lt; "Please enter the make: ";
      cin &gt;&gt; car[n].name; cout &lt;&lt; endl;
  
      cout &lt;&lt; "Please enter the year: ";
      cin &gt;&gt; car[n].year; cout &lt;&lt; endl;
      n++;
  }
  
      cout &lt;&lt; "Here is your collection:\n";
  
  int m = 0;
  while (m &lt; number)
  {
      cout &lt;&lt; car[m].year &lt;&lt; " " &lt;&lt; car[m].name &lt;&lt; endl;
      m++;
  }
  delete [] car;
  return 0;
  }
  </code></pre>