Hi @RPaun,
and welcome to the ROOT forum.
This does not seem a ROOT error, but a plain C++ problem.
Which line triggers the error? Can you remove all other lines?
If it’s fstream file;, as it seems from the error message: how are you executing that code? It works e.g. on lxplus:
[eguiraud@lxplus7117 ~]$ source /cvmfs/sft.cern.ch/lcg/views/LCG_98python3/x86_64-centos7-gcc10-opt/setup.sh
[eguiraud@lxplus7117 ~]$ root
fstream file; ------------------------------------------------------------------
| Welcome to ROOT 6.22/00 https://root.cern |
| (c) 1995-2020, The ROOT Team; conception: R. Brun, F. Rademakers |
| Built for linuxx8664gcc on Jun 14 2020, 15:54:05 |
| From tags/v6-22-00@v6-22-00 |
| Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
------------------------------------------------------------------
root [0] fstream file;
root [1] .q
root [3] .x tutorial_4.C
In file included from input_line_11:1:
/Users/rpaun/Desktop/Workspace/Examples/root-tutorials-examples/physics-matters-tutorial/tutorial_4.C:14:10: error: call to member function 'open' is ambiguous
file.open("data2.txt", ios::in);
~~~~~^~~~
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/fstream:1607:10: note: candidate function
void open(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/fstream:1611:10: note: candidate function
void open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in|ios_base::out)
^
In file included from input_line_11:1:
/Users/rpaun/Desktop/Workspace/Examples/root-tutorials-examples/physics-matters-tutorial/tutorial_4.C:24:10: error: no member named 'close' in 'std::__1::basic_fstream<char, std::__1::char_traits<char> >'
file.close();
~~~~ ^
root [4] .x tutorial_4.C
In file included from input_line_12:1:
/Users/rpaun/Desktop/Workspace/Examples/root-tutorials-examples/physics-matters-tutorial/tutorial_4.C:4:10:** **error:** **call to member function 'open' is ambiguous
file.open("data2.txt", ios::in);
~~~~~^~~~
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/fstream:1607:10: note: candidate function
void open(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/fstream:1611:10: note: candidate function
void open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in|ios_base::out)
^
In file included from input_line_12:1:
/Users/rpaun/Desktop/Workspace/Examples/root-tutorials-examples/physics-matters-tutorial/tutorial_4.C:15:10: error: no member named 'close' in 'std::__1::basic_fstream<char, std::__1::char_traits<char> >'
file.close();
Sorry for not providing you with the full code the first time. What am I doing wrong? Please note I am running this code on a MacOS. Please let me know if you need additional details.
Uhm I’m afraid I am not able to reproduce the problem (i.e. works fine on all systems I could try this on, but admittedly MacOS is not one of them). After all it’s really weird that the compiler thinks that call to open is ambiguous.
Besides what @Axel suggests, can you please try to use .x tutorial_4.C++ with two + signs at the end (it tells ROOT to compile the code using your system’s compiler)? That might help figure out which of the moving parts is causing the problem.
Also: can you call fstream file; file.open("data2.txt", ios::in) in a normal, compiled C++ program?
I used ifstream instead of fstream and it worked. I believe that the problem lies in the interpreter that MacOS uses.
Thank you both for taking the time to solve this.
Regards,
Remus