#include "TFile.h" #includeint main() { TFile file("my_file.root"); std::cout << "File title: " << file.GetTitle() << std::endl; return 0; }
#include "TFile.h" #includeThis example uses the TFile::Open() static function to open the ROOT file. If the file can't be opened, an error message is printed. Otherwise, the file's title is printed and the file is deleted. Both examples use TFile's GetTitle() function to retrieve the title of the file. This function returns a const char* pointer to the title string.int main() { TFile* file = TFile::Open("my_file.root"); if (!file) { std::cerr << "Error opening file!" << std::endl; return 1; } std::cout << "File title: " << file->GetTitle() << std::endl; delete file; return 0; }