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?
Can someone suggest something or explain something that I am missing?
Thanks!
in c# (psuedo:
public static List<Referral> Referrals = new List<Referral>();
//in loop:
var NewReferral = new Referral(referringURL.Trim(), referringWords.Trim().ToLower() , 1);
if ( NewReferral.URL == referringURL.Trim() ) {Referrals.Add(NewReferral);
in c++:
list<CollectedData> AllData;
ifstream myFile("test_data.txt");
if (myFile.fail()) {cout << "Error opening file"; return 0;}
else
{
cout << "File opened... \n";
while( getline(myFile, line) ) {
struct CollectedData;
//add property values
//add struct to struct list
}
}
(please do go into detail about when they automatically delete, it probably won't be helpful, but i'd like to know. thanks!)