# Output file is blank

**URL:** <https://root-forum.cern.ch/t/output-file-is-blank/59586>\
**Category:** Newbie\
**Created:** [June 7, 2024, 12:31pm UTC](https://root-forum.cern.ch/t/output-file-is-blank/59586 "2024-06-07T12:31:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lum\_totzin](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/e9a140/32.png) [@lum\_totzin](https://root-forum.cern.ch/u/lum_totzin)\
**Post date:** [June 7, 2024, 12:31pm UTC](https://root-forum.cern.ch/t/output-file-is-blank/59586/1 "2024-06-07T12:31:14Z")

</div>

* * *

_ROOT Version:_ 6.30/06

* * *

I want to print to a text file. I can print on the terminal but when I tried to print on the text file it is always blank. Please help.  
[Test.C](https://root-forum.cern.ch/uploads/short-url/GD60zR8bCZJNKm28Y39MWdgYjC.C) (5.1 KB)

---

<div class="post-metadata">

**Author:** ![mdessole](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mdessole/32/34021_2.png) [@mdessole](https://root-forum.cern.ch/u/mdessole)\
**Post date:** [June 7, 2024, 1:13pm UTC](https://root-forum.cern.ch/t/output-file-is-blank/59586/2 "2024-06-07T13:13:12Z")

</div>

Hello @lum_totzin,  
thanks for reaching out!

Can you be more precise about what you want to do? For example, what do you want to print?  
I took a look at your macro, but it looks kinda incomplete…

Cheers, Monica

---

<div class="post-metadata">

**Author:** ![lum\_totzin](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/e9a140/32.png) [@lum\_totzin](https://root-forum.cern.ch/u/lum_totzin)\
**Post date:** [June 7, 2024, 8:44pm UTC](https://root-forum.cern.ch/t/output-file-is-blank/59586/3 "2024-06-07T20:44:28Z")

</div>

Dear mdessole

I want to print out the following onto a textfile:  
outputFile \<\< "IP: " \<\< ip \<\< ", Channel: " \<\< nch \<\< ", X: " \<\< ch2Xtmp \<\< ", Y: " \<\< ch2Ytmp \<\< ", ADC: " \<\< nadc \<\< std::endl; Now I can print this on the terminal but not onto a textfile, even though I included a check to see if it opens successfully(see line 77-78). Yes I include pary of the macro that I think is relevant otherwise it is very long.

---

<div class="post-metadata">

**Author:** ![mdessole](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mdessole/32/34021_2.png) [@mdessole](https://root-forum.cern.ch/u/mdessole)\
**Post date:** [June 8, 2024, 2:14pm UTC](https://root-forum.cern.ch/t/output-file-is-blank/59586/4 "2024-06-08T14:14:35Z")

</div>

Dear @lum_totzin,

your question doesn’t seem to be related to ROOT. If you think it is, can you please explain how?

Cheers,  
Monica

---

<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:** [June 10, 2024, 7:47am UTC](https://root-forum.cern.ch/t/output-file-is-blank/59586/5 "2024-06-10T07:47:44Z")

</div>

It is working for me:

#### File test\_cout.C

```auto
#include <fstream>
#include <iostream>

void test_cout() {
   std::ofstream outputFile("output.txt"); // create a new output file or overwrite an existing one

   if (outputFile.is_open()) { // check if the file was opened successfully
      outputFile << "Hello, world!\n"; // write data to the file
      outputFile.close(); // close the file when done
      std::cout << "Data was written to output.txt\n";
   } else {
      std::cerr << "Error opening file\n";
   }
}

```

script execution:

```auto
% root test_cout.C -q
   ------------------------------------------------------------------
  | Welcome to ROOT 6.33.01 https://root.cern |
  | (c) 1995-2024, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for macosx64 on Jun 06 2024, 07:54:39 |
  | From heads/master@v6-31-01-2264-g2a92722afe |
  | With Apple clang version 15.0.0 (clang-1500.3.9.4) |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------------

Processing test_cout.C...
Data was written to output.txt
% cat output.txt 
Hello, world!
% 

```

---

<div class="post-metadata">

**Author:** ![lum\_totzin](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/e9a140/32.png) [@lum\_totzin](https://root-forum.cern.ch/u/lum_totzin)\
**Post date:** [June 15, 2024, 7:47pm UTC](https://root-forum.cern.ch/t/output-file-is-blank/59586/6 "2024-06-15T19:47:30Z")

</div>

Thanks @couet . I #include and it worked fine. Thank you very much!!

```auto

```
