Message: Re: atof() for Geant4? Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

More Re: atof() for Geant4? 

Keywords: G4String, double
Forum: Documentation and Examples
Re: None atof() for Geant4? (Aram)
Date: 28 Mar, 2008
From: Gabriele Cosmo <Gabriele Cosmo>

Hi,

> is there a built-in way to convert G4Strings into G4doubles?
> something like G4double G4atof(G4String);?

there is no such functions in Geant4.
You can easily code your own using the tools provided by the C++ language ...
Either, something like this:

#include <cstring>
G4double ConvertG4StringToDouble(const G4String& str)
{
  char* buf;
  return strtod(str.c_str(), &buf);
}

or:

#include <sstream>
G4double ConvertG4StringToDouble(const G4String& str)
{
  G4double vl;
  const char* cstr = str.c_str();
  std::istringstream is(cstr);
  is >> vl;
  return vl;
}

Cheers, Gabriele

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: atof() for Geant4?   (ateymura@yahoo.com - 28 Mar, 2008)
3 None: Re: atof() for Geant4?   (ateymura@yahoo.com - 28 Mar, 2008)
1 None: RE: atof() for Geant4?   (Makoto Asai - 28 Mar, 2008)
(_ None: RE: atof() for Geant4?   (Aram - 29 Mar, 2008)
(_ None: RE: atof() for Geant4?   (Aram - 30 Mar, 2008)
(_ None: RE: atof() for Geant4?   (Makoto Asai - 30 Mar, 2008)
 Add Message Add Message
to: "Re: atof() for Geant4?"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]