# Plotting a txt file

**URL:** <https://root-forum.cern.ch/t/plotting-a-txt-file/49140>\
**Category:** Newbie\
**Created:** [March 11, 2022, 10:34pm UTC](https://root-forum.cern.ch/t/plotting-a-txt-file/49140 "2022-03-11T22:34:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [March 11, 2022, 10:34pm UTC](https://root-forum.cern.ch/t/plotting-a-txt-file/49140/1 "2022-03-11T22:34:58Z")

</div>

Every time I tried to plot a histogram with a data it shows error in fstream, not sure if the error is on root or the C program.  
**rror:** **no matching constructor for initialization of ‘std::\_\_1::fstream’ (aka**

**’basic\_fstream’)**

```auto
TH1F *hist = new TH1F("hist","Histogram",100,0,100);
fstream file;
file.open("C07.txt", ios::in);
double value;
while(1)
    {
        file>>value;
        hist -> Fill(value);
        if (file.eof())break;

    }
    hist ->GetXaxis() ->SetTitle("data");
    hist ->GetYaxis()->SetTitle("Percentage");    
    

    TCanvas*c1 = new TCanvas();
    hist ->Draw();
    

}

```

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [March 12, 2022, 11:19am UTC](https://root-forum.cern.ch/t/plotting-a-txt-file/49140/2 "2022-03-12T11:19:13Z")

</div>

Try with

```auto
ifstream file;
file.open("C07.txt");

```
