"cout" cannot be used

ROOT Version: 6
Platform: Windows
Compiler: command prompt


sorry. Because English is inconvenient and Google Translated it into English, there may be some parts that do not make sense.

The image source code works for version 5 root but not for version 6 root.
Have you changed the settings such as not being able to use cout since version 6?

Hello and welcome to the ROOT forum!

There is nothing in ROOT 6 that would prevent cout from being used. I think the problem in this function is a missing return statement. The function signature would need to change into void kaida21(void) or you’d need to return an integer in the body of the function.

Cheers,
Jakob

Thank you for your reply!
I tried again with return, but only “pi:” is displayed on the screen and the calculation result of the essential pi is not displayed. And I’m sorry many times.

Strange, this second problem I cannot reproduce. Could you attach your macro as a file?

Try to replace << endl; by << "\n";

Can you copy and paste your source code here?
A screen dump is not really helpful.

What looks suspicious to me is the string “pi:”. Can it be that you really use “” characters (Unicode left and right double quotation marks) instead of "" characters (standard ASCII double quotation marks)?

1 Like

Thank you for your reply.
sorry. I tried replacing it, but the result did not change.

As @Wile_E_Coyote said, it looks like your quotes are the wrong ones. Can you try to replace them with ""?

Thank you for your kindness many times.
Paste the source code below.

#include <iostream>
#define N 1000

using namespace std;

int kadai211(void) {
	double cnt = 0.0;
	for (int i = 0; i < N; i++) {
		double x = (double)rand() / RAND_MAX;
		double y = (double)rand() / RAND_MAX;

		if ((x * x + y * y) <= 1) {
			cnt += 1.0;
		}
	}
	cout << "pi:" << cnt / N * 4.0 << endl;
return 0;
}

#include <cstdlib> // rand, RAND_MAX

BTW. Are you using the latest ROOT release?

This is exactly the problem with the wrong type of the double quotation marks.

I tried adding “#include <cstdlib>” but the result did not change.
I’m using root v6.24.00 now.

I have no problems with the source code from your previous post.

Thank you very much.
Reinstall root and try different things.

Even this simpler version is working with root 6.
kadai211.C (270 Bytes)

% root -l kadai211.C
root [0] 
Processing kadai211.C...
pi: 3.168
root [1] 

Thank you very much.
As a result of investigating, I found that there are some reports that version 6 malfunctions on Windows. So I tried installing version 5 and it was solved. Thank you for taking the time to respond.

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