How to output data to txt file?

I write codes as below.
2021-05-13 14-53-12屏幕截图
But the terminal do not execute it.

1 Like"/home/priyanshu/Documents/workingdir./Example/advanced/radioprotection/mytext.txt", std::ios::app);
file<<“energy deposited:\t” << edepStep/MeV<< G4endl;

like this, i think you can get. please try this and give the name of the directory where you want to save that file.

Goodmorning, I was interest in something similar. I can i save all the run output into a txt file? Thanks a lot

I am not sure what the problem is. C++ provides ways of writing data to file. Simply get the information you want (in your stepping action or similar) and use C++ to write it to file.

So, is your problem: “How to get the data”; or “How to write C++”?

In addition, in multithreading mode, you need to protect the output statements with mutex locks.

redirect all output (G4cerr, G4cout, everything the app prints out) to textfile in the command line:

./yourApp > logfile.txt

or separate err/out:

./yourApp 2>err.txt 1>out.txt

for windows, you would have to google yourself :wink:

I actually need it for Windows and couldn’t find it anywhere on google. If you can help me would be really appreciated.

I found it, thanks anyway!