Re: [ROOT] Using ifstream

From: pawan@rcf.rhic.bnl.gov
Date: Sun Aug 29 2004 - 12:12:58 MEST


Hi Zaldy

The error I think is in while loop:


while(fin.eof() == false) {
>    fin >> rn >> spl;
>   }

While declaration of ifstream you use (ifstream in) & in while loop you
use fin.
If you use in instead of fin in the while loop :
while(in.eof() == false){
in>> rn >> spl;
}

It will work.
Regards
Pawan

> Dear Folks,
>
> When not using Root Application, I used to write a code using ifstream in
> COMPILED Code like this below. Things are just Ok. But when I used this
> using root, I get a compilation error message as I also shown below.
>
> What is wrong with my code?
> Any Hint please.
>
> I have attached a small tar file reproducing this problem.
>
> I am using root Version   3.10/01  28 November 2003
> with gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
>
> Thanks in advance.
> Zaldy
>
>
> ===========================Compilation error message
> g++ -O -Wall -fPIC -Wno-deprecated -D_REENTRANT
> -I/CERN_SOFT/myroot/include/root   -c -o HitInfo.o HitInfo.cc
> In file included from HitInfo.cc:3:
> HitInfo.hh:37:39: warning: no newline at end of file
> HitInfo.cc: In member function `void HitInfo::Write_To_RootFile(char*)':
> HitInfo.cc:19: aggregate `std::ifstream fin' has incomplete type and
> cannot be
>    defined
> make: *** [HitInfo.o] Error 1
>
>
>
> ============================Sample  code
> #include <fstream.h>
> #include <ifstream.h>
> .....
> .....
>
> ifstream in;
> in.open("Filename.dat",ios::in);
>
>   Int_t rn, spl;
>
>   while(fin.eof() == false) {
>    fin >> rn >> spl;
>   }
>
> .......
> .......
>
>
> --
> Zaldy A. Nawang
>
>
>



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:09 MET