RE: [ROOT] Basic file stream operation in ROOT

From: Philippe Canal (pcanal@fnal.gov)
Date: Wed Jul 16 2003 - 21:19:09 MEST


Hi Exaos,

Currently CINT does not import/have the operator>> for ifstream and
std::string.

As a work around use a simple C-string:

   ifstream idx_in("evnt_index.txt",ios::in);
   char evnt_fn[512];
   idx_in >> evnt_fn;

> How to make sure a file is open in root? I use this code:
> Does the statement "assert()" work with CINT?

What you propose should work in CINT.  assert does work with CINT by
returning to the ROOT/CINT prompt (after an error message) rather than
stopping the program.

Cheers,
Philippe.

PS. Read the posting guidelines at
http://root.cern.ch/root/roottalk/RoottalkRules.html



-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Exaos Lee
Sent: Thursday, June 26, 2003 1:00 AM
To: roottalk@listbox.cern.ch
Subject: [ROOT] Basic file stream operation in ROOT


Dear rooter,
I want to read a string from an ASCII file. I use the following code:
---
ifstream idx_in("evnt_index.txt",ios::in);
std::string evnt_fn;
....
idx_in >> evnt_fn;
---
When root reaches "idx_in>>evnt_fn", it warns:
----
Error: operator>> not defined for basic_ifstream<char,char_traits<char>
> FILE:e2r_1.C LINE:60
*** Interpreter error recovered ***
----
How to solve this problem?

How to make sure a file is open in root? I use this code:
----
ifstream evnt_in;
...
evnt_in.open(evnt_fn, ios::in | ios::binary);
assert(evnt_in.is_open());
----
Does the statement "assert()" work with CINT?


Best regards.

Exaos



#################################################################
#################################################################
#################################################################
#####
#####
#####
#################################################################
#################################################################
#################################################################



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:13 MET