CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

how to convert string type to scalar type

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   October 15, 2009, 22:48
Smile how to convert string type to scalar type
  #1
Member
 
jingjing
Join Date: Mar 2009
Location: shanghai,China
Posts: 30
Rep Power: 8
zhajingjing is on a distinguished road
Hello everyone,

In a small post-processing program, I have to convert a string into a scalar:
Code:
int main(int argc, char *argv[])
{
    timeSelector::addOptions();
    argList::validArgs.append("fieldName"); 
    argList::validArgs.append("xValue");
#   include "setRootCase.H"
#   include "createTime.H"
    instantList timeDirs = timeSelector::select0(runTime, args);
#   include "createMesh.H"

    word fieldName(args.additionalArgs()[0]);
   word xValue(args.additionalArgs()[1]);
    
    Info <<xValue<<endl;
    
    ......     // ?
   scalar   x=       //   get the value from xValue, but xValue is a string---How???
Thanks for any help!
zhajingjing is offline   Reply With Quote

Old   October 16, 2009, 04:20
Default
  #2
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 14
l_r_mcglashan will become famous soon enough
You could use 'strtod' from the cstdlib.

http://www.cplusplus.com/reference/c...stdlib/strtod/
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   October 16, 2009, 07:23
Default
  #3
Member
 
jingjing
Join Date: Mar 2009
Location: shanghai,China
Posts: 30
Rep Power: 8
zhajingjing is on a distinguished road
I add the following,It worked.Thank you very much.
Code:
 #include <cstdlib>
...
   char* pEnd;
   scalar x=strtod(xValue.c_str(),&pEnd);
zhajingjing is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pressure instability with rhoSimpleFoam daniel_mills OpenFOAM Running, Solving & CFD 44 February 17, 2011 18:08
Flow Around a Cylinder ronaldo OpenFOAM 5 September 18, 2009 08:13
LiftDrag tool nuovodna OpenFOAM Running, Solving & CFD 45 September 2, 2009 17:56
Problem with compile the setParabolicInlet ivanyao OpenFOAM Running, Solving & CFD 6 September 5, 2008 20:50
Trimmed cell and embedded refinement mesh conversion issues michele OpenFOAM Other Meshers: ICEM, Star, Ansys, Pointwise, GridPro, Ansa, ... 2 July 15, 2005 04:15


All times are GMT -4. The time now is 21:02.