TString input = "1,2,3,4,5"; TObjArray *tokens = input.Tokenize(","); for (int i=0; iGetEntries(); i++) { TString token = ((TObjString*)tokens->At(i))->GetString(); int val = token.Atoi(); cout << "Token " << i << " = " << val << endl; } delete tokens;
ifstream file("input.txt"); TObjArray *tokens; TString line; while (getline(file,line)) { tokens = line.Tokenize(" "); // split by space for (int i=0; iThis code reads a text file containing multiple lines of text, and uses TString Tokenize to split each line into separate words based on the space character. The resulting substrings are then printed to the console.GetEntries(); i++) { TString token = ((TObjString*)tokens->At(i))->GetString(); cout << token << endl; } delete tokens; // free memory }