I have a file with 10 integers. I read the file and put it into a list. I then modify the list (add, delete, etc) and now I want to be able to save that list. So I have no idea how to take the items from my array list and save it into the file.
1) Read the file and put it into list:
ifstream intFile, floatFile;
ofstream intFileOut, floatFileOut;
SortedList<int> intList;
SortedList<float> floatList;
int a=0;
float b=0;
intFile.open("int.dat");
floatFile.open("float.dat");
while(intFile>>a)
{
intList.InsertItem(a);
a++;
}
while(floatFile >>b)
{
floatList.InsertItem(b);
b++;
}
intFile.close();
floatFile.close();
2) Modified the list
cout<<"------------------------------"<<endl;
cout<<"INT LIST: "<<endl;
cout<<"Adding 1 to list..."<<endl;
intList.InsertItem(1);
cout<<"Adding 2 to list..."<<endl;
intList.InsertItem(2);
cout<<"Deleting int 20 from the list..."<<endl;
intList.DeleteItem(20);
cout<<"------------------------------"<<endl;
cout<<"INTs in the list: "<<endl;
intList.GetNextItem(a);
cout<<"------------------------------"<<endl;
cout<<"Retriving int 30..."<<endl;
cout<<"Position of int 30: ";intList.RetrieveItem(30);cout<<endl;
3) Now I want to take the intList and save it to intFileOut, if that makes sense?
Any tips/help would be appreciated.
fstream(read & write) instead of separateifstreamandofstreamobjects.a++andb++seems unnecessary.