Re: [ROOT] iostream

From: Ingo Strauch (strauch@mail.desy.de)
Date: Mon Sep 29 2003 - 16:28:49 MEST


Dong Zhou wrote:
> 
> i feel there is something wrong with the 'fin >>' method.

It isn't ;-)


> my code is like this:
> // tmp.cpp
> void tmp(){
> ofstream fout ("tmp.dat");
> Double_t arr;
> 
> for(int i=0;i<3;++i){
>  fout << i*0.1;
> }

You should change that to

  for(int i=0;i<3;++i){
   fout << i*0.1 << " ";
  }

To separate the numbers by a blank. 


> fout.close();
> ifstream fin("tmp.cpp");
                    ^^^
Typo I guess ;-)


> for(i=0;i<3;++i){
>  fin >> arr;
>  cout << i << ' ' << arr << endl;
> }
> }
> 
> it should be 0 0.1 0.2
> but the output turns out to be 0.1 0.2 0.2
> it seems that it take 00.1 as 0.1

Exactly. Where should the program know from that 00.1 is meant as two
numbers?

What you write to the file is '00.10.2' which is interpreted as two
numbers, one being 00.10 and the other .2


> i am not sure if i have made any mistake. what is ur opinion?

When you change the code to also print a ' ' between the numbers it's
correct.

Cheers,
Ingo

P.S.: You should probably not write HTML formatted mails, they tend to
"eat" blanks and thus spoil the indentation of code.

-- 
"What're quantum mechanics?"
"I don't know. People who repair quantums I suppose."
                                     --Rincewind, Terry Pratchett "Eric"



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