|
[Sponsors] |
How to read a list of integers from a string? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
October 23, 2021, 11:05 |
How to read a list of integers from a string?
|
#1 |
Senior Member
ONESP-RO
Join Date: Feb 2021
Location: Somwhere on Planet Earth
Posts: 127
Rep Power: 5 |
Hello,
I am trying to convert a word (string) to a list as follows: Code:
List<Foam::label> indices; const word w = "(0 0 0)"; w >> indices; Any ideas? Thank you Last edited by NotOverUnderated; October 23, 2021 at 14:45. |
|
October 28, 2021, 16:06 |
|
#2 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
Sure, there are a few ways to do that, but FWIW you would want a string not a 'word' for the intermediate anyhow since a "word" generally should not be containing spaces! Code:
List<label> indices; // Use a IStringStream string str("( 1 2 3 )"); IStringStream is1(str); is1 >> indices; // Parse tokenize directly string str("( 1 2 3 )"); ITstream is2(str); is2 >> indices; // If you have read the input into a list of characters, received from a pipe or whatever List<char> charbuffer = ....; UIListStream is3(charbuffer); is3 >> indices. // Can even use the same thing for your string string str("( 1 2 3 )"); UIListStream is4(str.data(), str.length()); is4 >> indices. |
||
October 28, 2021, 19:33 |
|
#3 |
Senior Member
ONESP-RO
Join Date: Feb 2021
Location: Somwhere on Planet Earth
Posts: 127
Rep Power: 5 |
Many thanks for providing the answer. I thought that was not possible.
Thank you |
|
Tags |
conversion, list, openfoam, programming |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Read a vector list with IFstream and create IOobject from it | Sylv | OpenFOAM Programming & Development | 1 | October 9, 2017 16:25 |
Help for the small implementation in turbulence model | shipman | OpenFOAM Programming & Development | 25 | March 19, 2014 11:08 |
[swak4Foam] swak4Foam-groovyBC build problem | zxj160 | OpenFOAM Community Contributions | 18 | July 30, 2013 14:14 |
"parabolicVelocity" in OpenFoam 2.1.0 ? | sawyer86 | OpenFOAM Running, Solving & CFD | 21 | February 7, 2012 12:44 |
Read inside a class | tonyuprm | OpenFOAM | 12 | July 14, 2010 03:35 |