how to convert string type to scalar type
Hello everyone,
In a small post-processing program, I have to convert a string into a scalar: Code:
int main(int argc, char *argv[]) |
|
I add the following,It worked.Thank you very much.
Code:
#include <cstdlib> |
Convert to double
Hello, i got a similar problem.
I am trying to read from values from the thermophysical properties file. Here is my code: const fvMesh &PoP99 = V_.db().parent().objectRegistry::lookupObject<fvMe sh>(region2); const dictionary t1 = PoP99.thisDb().lookupObject<IOdictionary>("thermop hysicalProperties"); const dictionary t2(t1.subDict("mixture")); const dictionary transpks(t2.subDict("transport")); const auto sigmaLayer = transpks.lookup("sigmaL"); const auto st = sigmaLayer[0]; double q = 10.0; Info << st*q <<endl; obviously this dosent work because st has the datatype Foam::token amd q double. is there a way to convert from Foam::token to double? |
Quote:
Not really sure what your "sigmaL" represents. At the moment it simply represents a copy of a tokenList (which is the ITstream that the lookup method returns). If we assume that "sigmaL" is actually supposed to be a list of scalars I would write it like this: Code:
const fvMesh &PoP99 = V_.db().parent().objectRegistry::lookupObject<fvMe sh>(region2); |
Hello,
Thanks for your code, i manged to get it to work with a similar version. .get... did not work for me. I used this insted: scalar sigmaLayer (readScalar(transpks.lookup("sigmaL"))); thanks for the help |
Quote:
Glad you have it working. If you get a newer version, the dictionary get method is preferred since it will also check if there were any trailing tokens. |
ok good to know, thaks for the advice.
Unfortunately the get() function didnt work. The code compiled without any errors, but when i run the openFoam case i get the following Error: --> FOAM FATAL IO ERROR: (openfoam-2212) attempt to read beyond EOF file: constant/solidR/thermophysicalProperties.electricalProperties.elek transport.sigmaL at line 60. From virtual Foam::Istream& Foam::ITstream::read(Foam::token&) in file db/IOstreams/Tstreams/ITstream.C at line 450. FOAM exiting |
All times are GMT -4. The time now is 18:00. |