#include#include int main() { int myArray[5] = {1, 2, 3, 4, 5}; TArray arr(myArray, 5); TIterator* iter = arr.MakeIterator(); for (int i = 0; i < arr.GetSize(); i++) { cout << *iter << " "; iter->Next(); } cout << endl; delete iter; return 0; }
#includeIn this example, we create a list of integers and use `TList` to create a ROOT list object. We then loop through the list and create new `TObjInt` objects for each integer in the list, and add them to the `TList`. We then create an iterator with `TIter` and loop through the `TList` with `Next()`. We use `dynamic_cast` to ensure that the returned object is of type `TObjInt`, which has a `GetValue()` method to obtain the integer value. The library used is ROOT.#include #include
#include using namespace std; int main() { list mylist = {1, 2, 3, 4, 5}; TList* tl = new TList; for (auto it = mylist.begin(); it != mylist.end(); ++it) { tl->Add(new TObjInt(*it)); } TIter iter(tl); while (TObjInt* o = dynamic_cast (iter.Next())) { cout << o->GetValue() << " "; } cout << endl; delete tl; return 0; }