How to link ifstream?

Hi,

my first trial with root is shown at the bottom.
I just want to read an external file. As shown below,
in interpreted mode it runs fine, but the compiler gives some unexpected message.
As I understand, some header file is missing, and it is not because of me.

root [0] .x mydemo.c
ReadFile: Si_1s_3000.dat contains 2520 lines
root [1] .x mydemo.c++
Warning in : script has already been loaded in interpreted mode
Warning in : unloading F:\root\tutorials\mydemo.c and compiling it
c.dllin TWinNTSystem::ACLiC: creating shared library F:\root\tutorials\mydemo_
s22o.1_cint.cxx
s22o.3_cint.cxx
s22o.5_cint.cxx
s22o.7_cint.cxx
s21s_.cxx
F:\root\tutorials\s21s_.h(7) : fatal error C1083: Cannot open include file: ‘std
def.h’: No such file or directory
Error in : Compilation failed!
Error: Function mydemo() is not defined in current scope FILE: LINE:0
Possible candidates are…
filename line:size busy function type and name
!!!Dictionary position not recovered because G__unloadfile() is used in a macro!
!!
*** Interpreter error recovered ***
root [2]

Also, when I comment out the #include, practically no change:

root [0] .x mydemo.c++
c.dllin TWinNTSystem::ACLiC: creating shared library F:\root\tutorials\mydemo_
s12c.1_cint.cxx
s12c.3_cint.cxx
s12c.5_cint.cxx
s12c.7_cint.cxx
s12o_.cxx
F:\root\tutorials\s12o_.h(7) : fatal error C1083: Cannot open include file: ‘std
def.h’: No such file or directory
Error in : Compilation failed!
Error: Function mydemo() is not defined in current scope FILE: LINE:0
Possible candidates are…
filename line:size busy function type and name
*** Interpreter error recovered ***
root [1]

On XP, with interpreter it runs fine, too.
If the #include is commented out, the linked does not find it, OK.
If it is present, the compiler issues error message on redefining
ifstream and ofstream.

Do I wrong something? What is the correct way to use an ifstream
in the compiled version?

Thanks

Janos

#if !defined(CINT)
#include <istream.h>
#endif
Double_t *x;
Double_t *y;
void ReadFile(const char *FileName)
{
Int_t Index = 0; char buf[500];
ifstream stream(FileName);
bool FD = false; // assume failure
do {stream.getline(buf,sizeof(buf)); ++Index;
}
while (!stream.eof()); --Index; //Count total# of lines
printf(“ReadFile: %s contains %d lines\n”,FileName, Index);
}

void mydemo()
{
TCanvas c1 = new TCanvas(“c1”,“A Simple Graph Example”,200,10,700,500);
ReadFile(“Si_1s_3000.dat”);
x = new Double_t[100];
y = new Double_t[100];
for(Int_t i=0; i<100; i++)
{
x[i] = i;
y[i] = i
i;
}
TGraph G1 = new TGraph( 100, x, y);
G1->Draw("AC
");
}

You hadd missing includes and a wrong include.
Also, the include declarations is OK with normal CINT. You do not need the #ifdef.
See your code modified below

Rene

#include “Riostream.h”
#include “TCanvas.h”
#include “TGraph.h”

Double_t *x;
Double_t *y;
void ReadFile(const char *FileName)
{
Int_t Index = 0; char buf[500];
ifstream stream(FileName);
//bool FD = false; // assume failure
do {stream.getline(buf,sizeof(buf)); ++Index;
}
while (!stream.eof()); --Index; //Count total# of lines
printf(“ReadFile: %s contains %d lines\n”,FileName, Index);
}

void mydemo()
{
new TCanvas(“c1”,“A Simple Graph Example”,200,10,700,500);
ReadFile(“Si_1s_3000.dat”);
x = new Double_t[100];
y = new Double_t[100];
for(Int_t i=0; i<100; i++)
{
x[i] = i;
y[i] = i*i;
}
TGraph G1 = new TGraph( 100, x, y);
G1->Draw("AC
");
}

[quote=“brun”]You hadd missing includes and a wrong include.
Also, the include declarations is OK with normal CINT. You do not need the #ifdef.
See your code modified below

Rene

Thanks a lot for correcting me. Unfortunately, after making the correction,
there is no change:

Regards

Janos

root [2] .L mydemo.c
root [3] mydemo()
ReadFile: Si_1s_3000.dat contains 2520 lines
root [5] .x mydemo.c++
Warning in : script has already been loaded in interpreted mode
Warning in : unloading F:\root\tutorials\mydemo.c and compiling it
c.dllin TWinNTSystem::ACLiC: creating shared library F:\root\tutorials\mydemo_
sqk.1_cint.cxx
sqk.3_cint.cxx
sqk.5_cint.cxx
sqk.7_cint.cxx
s1kk_4.cxx
F:\root\tutorials\s1kk_4.h(7) : fatal error C1083: Cannot open include file: ‘st
ddef.h’: No such file or directory
Error in : Compilation failed!
Error: Function mydemo() is not defined in current scope FILE: LINE:0
Possible candidates are…
filename line:size busy function type and name
!!!Dictionary position not recovered because G__unloadfile() is used in a macro!
!!
*** Interpreter error recovered ***

I cannot reproduce your problem.
On which OS/compiler are you running?
Whi version of ROOT?
Did you run my test unmodified?

Rene

[quote=“brun”]I cannot reproduce your problem.
On which OS/compiler are you running?
Whi version of ROOT?
Did you run my test unmodified?

Rene[/quote]

Sorry for these missing items.
I am using 4.00/08 on a Win2k on a desktop and yes, I did run the test unmodified.
Even, on my laptop WinXP it runs ok (at least this part), see in another thread.

Today my Win2k system produced even more strange reply, see below:
it looks like that the “official” script runs OK, while mine is not found (?)
and especially the error message makes it mystic:
my script is in the tutorials subdirectory, together with hsimple.c
Why does ROOT want to look for it in the macros subdirectory?

Thanks

Janos

root [0] .x hsimple.c
hsimple : Real Time = 1.67 seconds Cpu Time = 1.53 seconds
root [1] .x mydemo.c
Error in TRint::ProcessFile: macro mydemo.c not found in path .;f:/root/macros
root [2]

.;f:/root/macros

As indicated in the message mydemo.c is not in the current directory of in the macro directory under f:/root
Either indicate a fullpathname or modify your .rootrc according (read the details in the ROOT Users’ Guide).

Philippe.

[quote=“pcanal”].;f:/root/macros

As indicated in the message mydemo.c is not in the current directory of in the macro directory under f:/root
Either indicate a fullpathname or modify your .rootrc according (read the details in the ROOT Users’ Guide).

Philippe.[/quote]

Well, I forgot to mention that I invoked ROOT from the tutorials subdirectory, where both hsimple.c and mydemo.c are located.

Janos

Then you should look for a different on your system between mymacro.c and hsimple.C (spelling, permissions, etc…). There is no reason why the 2 name ‘hsimple.c’ and ‘mydemo.c’ would be treated differently by ROOT without an underlying difference between the 2 files.

Philippe.