CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Dynamic Ofstream Filenames (https://www.cfd-online.com/Forums/openfoam-programming-development/120702-dynamic-ofstream-filenames.html)

HakikiCanakkaleli July 12, 2013 13:17

Dynamic Ofstream Filenames
 
Hi

== 1 ==
I would like to generate numerous
Code:

const scalar
names in which the prefix of these will be identical.

e.g. radius1, radius2, radius3 ... .

== 2 ==
To this end, I tried to use the standard library.

Code:

#include <string>
#include <sstream>

...

string fileNAme( const string& prefix, int index) // In order to name the output files dynamically.
  {
  ostringstream finalName;
  finalName << prefix << index;
  return finalName.str();
  }

== 3 ==

Code:


for (int i = 0; i < 100; i++)
{
fileNAme( "radius", i).c_str()
}

== 4 ==

I would like to re-write such a code in the OpenFOAM context. Is there anyone can suggest where I can start or how I can do this?

Many thanks in advance.

deepsterblue July 12, 2013 13:24

Simple.

Code:

word fileName = "radius"

for (label i = 0; i < nRadius; ++i)
{
  word newName = fileName + name(i);
}


HakikiCanakkaleli July 12, 2013 15:05

Many thanks!


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