Macro error: unknown type name 'cout' ROOT 6.06/02

Hi I’m tryng to run this macro example the following way:
root macro.c

{ #include <iostream> cout << " Hello" << endl; float x = 3.; float y = 5.; int i = 101; cout <<" x = "<<x<<" y = "<<y<<" i = "<<i<< endl; }

Output:

root [1] .x macro.c /stash2/user/tkorokn/workflows/outputs/1485500180/./test.c:4:5: error: unknown type name 'cout' cout << " Hello" << endl; ^ /stash2/user/tkorokn/workflows/outputs/1485500180/./test.c:4:10: error: expected unqualified-id cout << " Hello" << endl; ^ /stash2/user/tkorokn/workflows/outputs/1485500180/./test.c:8:5: error: unknown type name 'cout' cout <<" x = "<<x<<" y = "<<y<<" i = "<<i<< endl; ^ /stash2/user/tkorokn/workflows/outputs/1485500180/./test.c:8:10: error: expected unqualified-id cout <<" x = "<<x<<" y = "<<y<<" i = "<<i<< endl;

Now after this if I type:

root [2] cout << " Hello" << endl; Hello

It works. Why does it not work with the macro?

Thanks!
Tibor

Hi TIbor,

it is not a good idea to include an stl header within a macro, as much as including it within the scope of an ordinary function in a library/program independent from root compiled with gcc/clang.
As a side note, all the relevant classes/routines/templates in the std namespace are already available at the root prompt / in macros even without specifying “std::”.

Cheers,
D