title: C++ creating and collecting structs in a loop
body: <p>I want to create a struct from data harvested by line from a file. Each line necessitates a new struct, and the lines are accessed in a while loop. In C# I did this by creating anonymous structs and adding them to a list of structs. C++ would seem not to allow anonymous structs. I tried naming them with an incrementing variable, but this did not work, as the variable name was taken literally - regardless, I would prefer not to be forced to use this method as I hate the idea of irrelevant names. I suppose I could name the struct by a unique property, but, obviously, I would rather use a property as. . . a property. Besides, what if they are not all necessarily unique?</p>
  
  <p>Can someone suggest something or explain something that I am missing?</p>
  
  <p>Thanks!</p>
  
  <p>in c# (psuedo:</p>
  
  <pre><code>public static List&lt;Referral&gt; Referrals = new List&lt;Referral&gt;();
  
  //in loop:
  var NewReferral = new Referral(referringURL.Trim(), referringWords.Trim().ToLower() , 1);
  if ( NewReferral.URL == referringURL.Trim() )  {Referrals.Add(NewReferral);
  </code></pre>
  
  <p>in c++:</p>
  
  <pre><code> list&lt;CollectedData&gt; AllData;
  
   ifstream myFile("test_data.txt");
   if (myFile.fail()) {cout &lt;&lt; "Error opening file"; return 0;}
   else
   {
    cout &lt;&lt; "File opened... \n";
    while( getline(myFile, line) ) {
     struct CollectedData;
                          //add property values
                          //add struct to struct list
    }
   }
  </code></pre>
  
  <p><em>(please do go into detail about when they automatically delete, it probably won't be helpful, but i'd like to know. thanks!)</em></p>