Hello, my problem is very trivial and easy to handle, but it can cause some trouble. When I try to convert a G4int to a G4String, everything works fine - except with the number 47. The output of the commands: >> G4int i = 47; >> G4cout << "Here is the result of (G4String)(i): " << (G4String)(i) << G4endl; looks >> Here is the result of (G4String)(i): / As you can see, for Integer 47 I get the ASCII-character "/" which has a decimal code of 47. My system is Scientific Linux, Kernel 2.6.18, Geant4.9.1. Best regards, Robert Freudenberg
Indeed forcing a cast of an integer to a string is NOT supposed to happen, and G4String is not supposed to convert a number to its corresponding string representation. To achieve this you may want to use the tools that C++ provides you. I.e, a simple function like the following would do the job: G4String ItoS(G4int i) { std::ostringstream os; os << i; return G4String(os.str()); }
Dear Gabriele Cosmo, I'm sorry for my wrong assumption. I supposed that I had read this way of conversion in one of the examples - but it wasn't so... Your small function does the job very well :-)