To fill a histogram by reading text file

{
   TH1F *h = new TH1F("h", "example histogram",1000,4.,8.);
   ifstream inp; double x;
   inp.open("expo.dat");
   for (int i=1; i<=1000; i++) {
      inp >> x;
      h->SetBinContent(i,x);
   }
   h->Draw();
}