CFD Online Discussion Forums

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

HakikiCanakkaleli July 12, 2013 12: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 12:24

Simple.

Code:

word fileName = "radius"

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


HakikiCanakkaleli July 12, 2013 14:05

Many thanks!


All times are GMT -4. The time now is 03:42.