# Create n outut files

**URL:** <https://root-forum.cern.ch/t/create-n-outut-files/43492>\
**Category:** Newbie\
**Created:** [February 10, 2021, 2:41pm UTC](https://root-forum.cern.ch/t/create-n-outut-files/43492 "2021-02-10T14:41:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GiuliaH](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@GiuliaH](https://root-forum.cern.ch/u/GiuliaH)\
**Post date:** [February 10, 2021, 2:41pm UTC](https://root-forum.cern.ch/t/create-n-outut-files/43492/1 "2021-02-10T14:41:59Z")

</div>

Hi,  
I have a 10k events data file and I would like to create 10 output files to store the mean signal calculated over 1000 waveforms.  
I am trying with

```auto
   char out_name[10];

   for(i=0; i<10;i++){
      sprintf(out_name, "WF_%d.dat", i);
      ofstream file1= (out_name);
   }

```

but this is not working!  
the error I get is:

```auto
error: no viable conversion from 'char [10]' to 'std::__1::ofstream' (aka
      'basic_ofstream<char>')

```

can anybody help me with that?

---

<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:** [February 10, 2021, 2:50pm UTC](https://root-forum.cern.ch/t/create-n-outut-files/43492/2 "2021-02-10T14:50:59Z")

</div>

With ROOT you can use `Form`

```auto
   for (i=0; i<10;i++) {
      ofstream file1= (Form("WF_%d.dat", i));
   }

```

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [February 10, 2021, 2:52pm UTC](https://root-forum.cern.ch/t/create-n-outut-files/43492/3 "2021-02-10T14:52:15Z")

</div>

[`std::ofstream file1(out_name);`](http://www.cplusplus.com/reference/fstream/ofstream/)

---

<div class="post-metadata">

**Author:** ![GiuliaH](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@GiuliaH](https://root-forum.cern.ch/u/GiuliaH)\
**Post date:** [February 10, 2021, 2:55pm UTC](https://root-forum.cern.ch/t/create-n-outut-files/43492/4 "2021-02-10T14:55:13Z")

</div>

I tried but I had a similar error:  
/Users/hull/Lavoro/PowderO/Data\_WC/ZWO/WF\_100.C:273:15: error: no viable conversion from ‘char \*’ to 'std::\__1::ofstream’ (aka  
‘basic\_ofstream’)  
ofstream file1=(Form("WF_%d.dat",i));  
^ ~~~~~~~~~~~~~~~~~~~~~  
/Library/Developer/CommandLineTools/usr/bin/…/include/c++/v1/iosfwd:146:32: note: candidate constructor (the implicit copy constructor) not viable: no known  
conversion from ‘char \*’ to ‘const std::\_\_1::basic\_ofstream\<char,  
std::\_\_1::char\_traits \> &’ for 1st argument  
class \_LIBCPP\_TEMPLATE\_VIS basic\_ofstream;  
^  
/Library/Developer/CommandLineTools/usr/bin/…/include/c++/v1/fstream:1374:5: note: candidate constructor not viable: no known conversion from ‘char \*’ to  
‘std::\_\_1::basic\_ofstream\<char, std::\_\_1::char\_traits \> &&’ for 1st  
argument  
basic\_ofstream(basic\_ofstream&& \_\_rhs);  
^  
root [1]

---

<div class="post-metadata">

**Author:** ![GiuliaH](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@GiuliaH](https://root-forum.cern.ch/u/GiuliaH)\
**Post date:** [February 10, 2021, 2:59pm UTC](https://root-forum.cern.ch/t/create-n-outut-files/43492/5 "2021-02-10T14:59:11Z")

</div>

this is working thanx a lot!
