Printing in terminal crashes root

Hi fellow physicts,

ROOT crashes when I try to print integers, doubles or floats with cout or printing a new line with endl. However, printing strings with coutworks fine, printing new lines with \n works too and for example drawing histograms in TCanvas works well too.

I have no idea how to fix this, does anyone know where the problem comes from? Everything worked fine until yesterday evening while I changed nothng. See below for an example of what kind of code works and what crashes ROOT.

using namespace std;
#include<iostream>
#include "vector"
#include <string>


void test() {

    string str = "Hello world!";

    cout << str; // Works
    cout << str << "\n"; // Works
    cout << str << endl; // Crashes


    int i = 2;
    int j = 3 + 2;

    cout << Form("i = %d", i); // Works
    cout << Form("j = %d", j); // Works
    cout << i; // Crashes
    
}

Kind regards,

Elias


Please read tips for efficient and successful posting and posting code

ROOT Version: ROOT 6.18/04
Platform: Windows 10
Compiler: Not Provided


@bellenot can you please take a look when you will have time, maybe it is Windows related problem?

Hi,

This is a known issue (on Windows only) that might have been solved in more recent version of ROOT. For example, with ROOT master:

C:\Users\bellenot\rootdev\Forum>root -l test.cxx
root [0]
Processing test.cxx...
Hello world!Hello world!
Hello world!
i = 2j = 52
root [1]

And after adding \n and <<endl, as shown below:

   cout << Form("i = %d\n", i); // Works
   cout << Form("j = %d\n", j); // Works
   cout << i << endl; // Crashes

It gives:

C:\Users\bellenot\rootdev\Forum>root -l test.cxx
root [0]
Processing test.cxx...
Hello world!Hello world!
Hello world!
i = 2
j = 5
2
root [1]

Cheers, Bertrand.

You said that it is a known issue on Windows. The weird thing is that everything was working ok, and suddenly not anymore. When I’m using endl or try to print anything else than a string, ROOT crashes.

Is it possible that ROOT upgrades automatically to a newer version and in the newer version this issue arises again? Because I don’t understand how else this issue suddenly can appear. I’ve had this issue before, but then it was solved the next day.

No, ROOT cannot update anything automatically. Did you update anything else on your computer, like Visual Studio or the Windows 10 SDK?

I’m using VS Code and I haven’t updated it, but it could be that it has update automatically. I’m not using Windows 10 SDK.

But even if I’m writing my code in Windows Notepad and the macro only consists of one line
std::cout << 2; or std::cout << std::endl; makes ROOT crashes, while std::cout << "2"; or std::cout << Form("%d", 2); works fine.

OK, so you can most probably use "\n" instead of std::endl, like for example: std::cout << Form("%d\n", 2);, or std::cout << i << "\n";

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.