title: Assigning a string element to a struct in an array of structs
body: <p>I am writing a function that reads various properties, including a string, from a csv file and assigns it to a relevant element of a struct which happens to be in an array of similar structs.</p>
  
  <p>Whenever I attempt to assign value to:</p>
  
  <pre><code>materialLookup[v-1].name 
  </code></pre>
  
  <p>the program crashes.</p>
  
  <pre><code>MaterialL 
  </code></pre>
  
  <p>is a struct with a <code>string</code> element called <code>name</code> that looks like this:</p>
  
  <pre><code>    struct MaterialL {
      string name;
      double sigma;
      double corLength;
      double mu;
      double muPrime;
      double ep;
      double epPrime;
  };
  </code></pre>
  
  <p>I have checked that I am reading the <code>string</code> from the csv file correctly and in this case, it is "Drywall". The program always crashes before I am able to <code>cout&lt;&lt;"hey";</code> on the next line. My only thought is that because the program doesn't know the size of the <code>string</code> before I assign it, it doesn't leave any memory for it. If so how can I rectify this?</p>
  
  <pre><code>   unsigned int getMatLookUp(string filename)
  {
      int nLines = getNumOfLines(filename);
      cout &lt;&lt; nLines;
      materialLookup = (MaterialL*)alignedMalloc(nLines * sizeof(MaterialL));
      ifstream file(filename);
      int v = 0;
      string value;
  
      if (file.is_open() &amp;&amp; fileExists(filename))
      {
          //flush title line
          for (int p = 0; p &lt; 6; p++){ std::getline(file, value, ',');  }std::getline(file, value);
          v++;
          //get all the materials
          while (v &lt; nLines -1)
          {
              std::getline(file, value, ',');
              cout &lt;&lt; value&lt;&lt;"\n\n";
              materialLookup[v - 1].name = value;
              cout &lt;&lt; "hey";
              std::getline(file, value, ',');
              cout &lt;&lt; value &lt;&lt; "\n\n";
              materialLookup[v - 1].sigma = stod(value);
              std::getline(file, value, ',');
              materialLookup[v - 1].corLength = stod(value);
              std::getline(file, value, ',');
              materialLookup[v - 1].mu = stod(value);
              std::getline(file, value, ',');
              materialLookup[v - 1].muPrime = stod(value);
              std::getline(file, value, ',');
              materialLookup[v - 1].ep = stod(value);
              std::getline(file, value);
              materialLookup[v - 1].epPrime = stod(value);
              v++;
          }
          file.close();
      }
      else
      {
          cout &lt;&lt; "Unable to open file when loading material lookup in function getMatLookUp press enter to continue\n";
          cin.get();
      }
      return(0);
  }
  </code></pre>