Tokenizing a string

Hi,

I have some problem with tokenizing a string.
My script is shown at the bottom. I wanted to read a data file
and read its contents through using Tokenize.
The output produced is:
root [1] .x mydemo.C
1:(2 tokens) =116.45 17243
01
1=116.4
1=17203.3
2:(2 tokens) =116.35 17121.4
01
2=116.3
2=17389.3

so I have the feeling that the ReadLine and ReadToken work perfectly,
but here I cannot use more than one delimiter. Here the number of
tokens is recognized correctly, but the token strings seem to be empty.
Do I wrong something?

A related problem, shown by the output below:
root [2] .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_
sac.1_cint.cxx
sac.3_cint.cxx
sac.5_cint.cxx
sac.7_cint.cxx
s21g_.cxx
F:\root\tutorials\s21g_.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 [3]

What is wrong here? Even I do not understand the error message.

Thanks for your help in advance

Janos

#include “Riostream.h”
#include “TCanvas.h”
#include “TGraph.h”
#include “TString.h"
Double_t *x;
Double_t *y;
void ReadFile(const char FileName)
{
Int_t Index = 0; char buf[500]; char delimiters[] = " \t\n;";
ifstream stream(FileName);
bool FD = false; // assume failure
do {stream.getline(buf,sizeof(buf)); ++Index;
}
while (!stream.eof()); --Index; //Count total# of lines
{
ifstream stream(FileName);
TString token;
for(int i = 1; i<10; i++)
{
token.ReadLine(stream);
TObjArray
Strings = token.Tokenize(delimiters);
printf(”%i:(%i tokens) =%s\n",i, Strings->GetEntriesFast(), token.Data());
if(Strings->GetEntriesFast())
{
for(int j = 0; j< Strings->GetEntriesFast(); j++)
{
TString T = (TString)Strings->At(j);
printf("%d=%s",j,T->Data());
}
printf("\n");
}
token.ReadToken(stream);
printf("%d=%s\n",i,token.Data());
token.ReadToken(stream);
printf("%d=%s\n",i,token.Data());
Strings->Delete();
}
printf(“File ended OK\n”);
}
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
");
}

Please , make it possible to run your demo by supplying :

Si_1s_3000.dat !

[quote=“Eddy Offermann”]Please , make it possible to run your demo by supplying :

Si_1s_3000.dat ![/quote]
Hi,

I guessed that the content is clear from the output:
it is a two-column data array, separated by spaces, two items per line,
like this:

116.45 17243
116.4 17203.3
116.35 17121.4
116.3 17389.3
116.25 17191.6
116.2 17046.6
116.15 17141.7
116.1 17210.2
116.05 17291.7
116 17196.6
115.95 17230.6
115.9 17311.6
115.85 17378.4

and some more 2500 similar lines.

Regards

Janos

This problem and the solution are the same as this other post