# TCanvas::Print wont take a variable as an argument

**URL:** <https://root-forum.cern.ch/t/tcanvas-print-wont-take-a-variable-as-an-argument/50943>\
**Category:** Newbie\
**Tags:** root\
**Created:** [July 25, 2022, 8:53am UTC](https://root-forum.cern.ch/t/tcanvas-print-wont-take-a-variable-as-an-argument/50943 "2022-07-25T08:53:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hawexrutile](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/hawexrutile/32/30053_2.png) [@hawexrutile](https://root-forum.cern.ch/u/hawexrutile)\
**Post date:** [July 25, 2022, 8:53am UTC](https://root-forum.cern.ch/t/tcanvas-print-wont-take-a-variable-as-an-argument/50943/1 "2022-07-25T08:53:02Z")

</div>

I wanted to loop over a block of code that calls a function (Loop())to create a histogram and then save it as a .png. TCanvas::Print is giving me an argument error as it only accepts a string as an argument. Is there any other way to do this? Any help would be appreciated.

```auto
   for (int i=0;i<N;i++){ 
      TCanvas *canva = new TCanvas("canva","Pt vs v2 and v3 for Proton, Pion and Kaon",1000,1000); 
      this->Loop(i,canva);
      canva->Print("./Plot/g"+to_string(i)+".png");        
      };

```

[Here](https://github.com/hawexrutile/SummerProject/blob/8fda24cdf8eb3bcaf53514b48ecb35bf11998c9e/6%20AMPT%20Practise/6%20v2%20ROOT%20Method/check.C) is a link to the actual code.

\_ROOT Version:6.26  
\_Platform: Windows  
\_Compiler: Clang

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [July 25, 2022, 8:55am UTC](https://root-forum.cern.ch/t/tcanvas-print-wont-take-a-variable-as-an-argument/50943/2 "2022-07-25T08:55:21Z")

</div>

```auto
canva->Print(Form("./Plot/g%d.png",i));   

```
