CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   How do I convert scalar to word (https://www.cfd-online.com/Forums/openfoam-solving/165000-how-do-i-convert-scalar-word.html)

bala_gk1988 January 7, 2016 04:29

How do I convert scalar to word
 
I want to convert a number to a string in openfoam.

Code:

scalar count(11);
    word fieldName(count);
    Info << fieldName << endl;

If I execute the above piece of code I get the following error

word::stripInvalid() called for word
For debug level (= 2) > 1 this is considered fatal
Aborted (core dumped)

What seems to be the problem here?
Thankyou

bala_gk1988 January 8, 2016 02:11

Never mind. Converting scalar to word should be done like this

Code:

word fieldName(name(i));

hamedhiv September 28, 2019 14:33

name function
 
you can use name function. like this:
Code:

scalar a(0);

word b =Foam::name(a);

the name function defined here

$FOAM_SRC/OpenFOAM/primitives/ints


All times are GMT -4. The time now is 11:16.